Hi,
I am use following code to find IP address of machine in C#.write following code in class file.
when build the solution it gives following error
1.The best overloaded method match for 'string.String(char*)' has some invalid arguments
2.Argument '1':cannot convert from 'string' to 'char*'
How to solve this error and access this class file in form

public static int MainIP(string [] args)
        {
            String strHostName = new String("");

            if (args.Length == 0)
            {
              
                strHostName = Dns.GetHostName();
                Console.WriteLine("Local Machine Name :" + strHostName);
            }
            else
            {
                strHostName = args[0];
            }

            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            IPAddress[] addr = ipEntry.AddressList;

            for (int i = 0; i < addr.Length; i++)
            {
                Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
            }
            return 0;
        }

The code for find IP address and machine name in Windows Programming

private void button1_Click(object sender, EventArgs e)
        {
            
            string myHost = System.Net.Dns.GetHostName();

            System.Net.IPHostEntry myIPs = System.Net.Dns.GetHostEntry(myHost);

            // Loop through all IP addresses and display each 

            foreach (System.Net.IPAddress myIP in myIPs.AddressList)
            {

                MessageBox.Show(myIP.ToString());

            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.