6

I try to convert Ip Address to uint:

IPAddress requstedIpAddress;
uint requesteIpAddressUint = (uint)IPAddress.Parse(requstedIpAddress.ToString()).Address;

And got this warning:

'System.Net.IPAddress.Address' is obsolete: 'This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons.

What does it mean and should i use some other way to do that ?

mark yer
  • 403
  • 6
  • 12

1 Answers1

6

The deprecation warning tells you that in the next update of your library which has IPAddress defined, will no longer have IPAddress.Address as a property. So your code will fail to compile after the next update to the library.

If you go to the documentation for IPAddress.Address it notes that the property is obsolete and should instead use IPAddress.GetAddressBytes.

The deprecation of IPAddress.Address is due to the adoption of IPv6 which is 128 bits while C# type long, which is actually a System.Int64, is only 64 bits.

Nadir Muzaffar
  • 4,772
  • 2
  • 32
  • 48
  • So it's better using IPAddress.GetAddressBytes, what about if i have an IPv^ address ? – mark yer Oct 03 '15 at 08:36
  • `IPAddress.GetAddressBytes` returnes `bytes[]` so that its can support IP address v4 and v6 and possibly next iterations though thats not likely for some time. – Nadir Muzaffar Oct 03 '15 at 14:23