Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3742
  • Last Modified:

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

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
Natural_Demon
Asked:
Natural_Demon
1 Solution
 
philipjonathanCommented:

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

Open in new window

0
 
AUmidhCommented:
Try this

private IPAddress localaddr = IPAddress.Parse("127.0.0.1");
0
 
margajet24IT Business AnalystCommented:
IPAddress localaddr =  IPAddress.Parse("127.0.0.1");
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Natural_DemonAuthor Commented:
thanks you for the promp rely,

IPAddress localaddr =  IPAddress.Parse("127.0.0.1"

how to get addres of localhost?
0
 
philipjonathanCommented:
localhost is always '127.0.0.1'
0
 
Rahul Goel ITILSenior Consultant - DeloitteCommented:

//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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now