none
Can anyone help me with this small section of code? I am trying to get rid of the green line.

    Question

  •                 if (enter == "ip" || enter == "IP")
                    {
                        string hostName = Dns.GetHostName();
                        string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
                        Console.WriteLine(hostName);
                        Console.WriteLine("My IP Address is :" + myIP);
                        Console.ReadKey();
                    }

    This is the code that I am trying to get rid of which is the Dns.GetHostByName(string).

    I am trying to figure out how to get rid of the green line because it says that it does not need it.

    Monday, October 31, 2016 6:49 PM

Answers

  • Hi Sara

    It is fixed now, I understand the problem, it was due to my understanding of the structure of my program but I appreciate the information that you have given.

    Thanks

    YAT32

    Tuesday, November 1, 2016 11:37 AM

All replies

  • Can you please be more specific? Which line is green? What is the exact wording of the interpretation?
    Monday, October 31, 2016 6:55 PM
  • Oh yes, It is this line "Dns.GetHostByName(hostName)"

    Btw, the host name is a string, which in my case you do not have to worry because I can sort it.


    • Edited by YAT32 Monday, October 31, 2016 7:04 PM
    Monday, October 31, 2016 6:58 PM
  • If you want I could give you my program so that you can fix this dilemma.
    Monday, October 31, 2016 11:17 PM
  • Hi YAT32,

    Welcome to the MSDN forum.

    I tried to copy your code into my project and I found there is a warning message as below:

    >>'Dns.GetHostByName(string)' is obsolete: 'GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202'

    And there is a green wavy line under the method Dns.GetHostByName(hostName), do you mean this, right?

    If so, you can try to use the method Dns.GetHostEntry Method (String) to replace the above obsolete method like the following screenshot, and you can define the parameter in the AddressList per your requirement.

    If not, please share the more detail information about your issue and upload your current solution to https://onedrive.live.com/ and share the link in here.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, November 1, 2016 8:20 AM
    Moderator
  • Hi Sara

    It is fixed now, I understand the problem, it was due to my understanding of the structure of my program but I appreciate the information that you have given.

    Thanks

    YAT32

    Tuesday, November 1, 2016 11:37 AM
  • Hi YAT32,

    I'm so glad to hear that your issue is solved and thank you for your sharing.

    If you have any other issue, please feel free to let me know.

    BTW, if you think my reply or your reply is helpful for other community members who have the same or similar issue, please mark it as answer, it will help them to easier search this information, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 2, 2016 1:11 AM
    Moderator