Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does IPAddress constructor take Int64 instead of UInt32?

Tags:

c#

.net

Why does IPAddress constructor take Int64 instead of UInt32? According to Reflector the address is stored as an Int64 internally (m_Address) and the constructor validates it to be within the range valid for UInt32. So I'm just curious why it uses Int64 and not UInt32.

And before anyone says IPv6.. IPv6 is bigger than Int64 and is stored as an array of UInt16. The Int64 constructor is only used to generate IPv4 addresses.

like image 596
Samuel Neff Avatar asked Feb 05 '10 21:02

Samuel Neff


1 Answers

Probably because in the Common Language Specification (CLS) of the Common Language Infrastructure (CLI) standard, unsigned types are not required to be supported by a language so they used the smallest signed type that will hold all the possible unsigned values.

The .NET Framework class library includes types that correspond to the primitive data types that compilers use. Of these types, the following are CLS-compliant: Byte, Int16, Int32, Int64, Single, Double, Boolean, Char, Decimal, IntPtr, and String.

like image 88
Michael Burr Avatar answered Nov 08 '22 05:11

Michael Burr