Solved

c#  why?,howto? Cannot implicitly convert type 'string' to 'System.Net.IPAddress'

Posted on 2008-06-19
8
3,303 Views
Last Modified: 2008-08-13
private IPAddress localaddr = Dns.GetHostEntry(textBox1.Text).AddressList[0].ToString();//"127.0.0.1";


private IPAddress localaddr = "127.0.0.1";


myListener = new TcpListener(localaddr,port);


localaddr, i'm stuck here, for debugging.

// Cannot implicitly convert type 'string' to 'System.Net.IPAddress'
0
Comment
Question by:Natural_Demon
8 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21828272

private IPAddress localaddr = IPAddress.Parse("127.0.0.1");
myListener = new TcpListener(localaddr,port);

Open in new window

0
 
LVL 7

Expert Comment

by:AUmidh
ID: 21828278
Try this

private IPAddress localaddr = IPAddress.Parse("127.0.0.1");
0
 
LVL 10

Expert Comment

by:margajet24
ID: 21828284
IPAddress localaddr =  IPAddress.Parse("127.0.0.1");
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Natural_Demon
ID: 21828494
thanks you for the promp rely,

IPAddress localaddr =  IPAddress.Parse("127.0.0.1"

how to get addres of localhost?
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 125 total points
ID: 21828558
localhost is always '127.0.0.1'
0
 
LVL 9

Expert Comment

by:Rahul Goel ITIL
ID: 21828573

//For parsing the string to IP
IPAddress ip =  IPAddress.Parse("127.0.0.1")
 
// To get the localhost IP
IPHostEntry iphost = Dns.GetHostByName(Dns.GetHostName());
IPAddress[] addr = iphost.AddressList;
 
for (int i = 0; i < addr.Length; i++)
{
                listBox1.Items.Add(string.Format("IP Address {0}: {1} ", i, addr[i].ToString()));
}

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question