Samuel Neff
Samuel Neff

Reputation: 74949

Why does IPAddress constructor take Int64 instead of UInt32?

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.

Upvotes: 8

Views: 617

Answers (1)

Michael Burr
Michael Burr

Reputation: 340446

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.

Upvotes: 12

Related Questions