Code for IP Address Comparison and Conversion in C#?



Code for IP Address Comparison and Conversion in C#?..

Answer / Santosh Kumar Bhagat

You can compare two IP addresses using `IPAddress.TryParse()` to convert IP strings to `IPAddress` objects, and then compare them:n```csharpnpublic static bool CompareIP(string ip1, string ip2) {n IPAddress addr1;n IPAddress addr2;n if (!IPAddress.TryParse(ip1, out addr1) || !IPAddress.TryParse(ip2, out addr2)) return false;n return addr1.Equals(addr2);n}nTo convert an IP address to a string representation, you can use the `ToString()` method:n```csharpnstring ip = "255.255.255.0";nIPAddress ipAddr = IPAddress.Parse(ip);nstring ipStr = ipAddr.ToString();n``

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Code Interview Questions

working with arrays

1 Answers  


How to export 2 datatables of a single dataset to 2 different worksheets of a single MSExcel file ?

1 Answers   Eastcom Systems,


program for straight line(y=mx+c)

1 Answers   Mind Tree,


how to change password in .net with c # with ado.net and also SQL server 2008 change password

1 Answers  


Code for Working with Files under a Directory?

1 Answers  


Event Handling in C# Triggering a Button

1 Answers  


Write a program to convert postfix expression to infix expression.

1 Answers   Mind Tree,


how can i split sting in textbox in windows application using c# .net

2 Answers  


program for string reverse(eg:- i am boy -> boy am i)

8 Answers   Black Pepper, Infosys, Mind Tree,


How to Link Different Data Sources Together?

1 Answers  


"c sharp" code for factorial using static variables

9 Answers  


Coding for Manipulate XML File Data Using C#?

1 Answers  


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)