Export (0) Print
Expand All

uint

The uint keyword denotes an integral type that stores values according to the size and range shown in the following table.

Type Range Size .NET Framework type
uint 0 to 4,294,967,295 Unsigned 32-bit integer System.UInt32

Literals

You can declare and initialize a variable of the type uint like this example:

uint myUint = 4294967290;

When an integer literal has no suffix, its type is the first of these types in which its value can be represented: int, uint, long, ulong. In this example, it is uint.

You can also use the suffix u or U, like this:

uint myUint = 123U;

When you use the suffix U or u, the literal type is determined to be either uint or ulong according to its size. In this example, it is uint.

Conversions

There is a predefined implicit conversion from uint to long, ulong, float, double, or decimal. For example:

float myFloat = 4294967290;   // OK: implicit conversion to float

There is a predefined implicit conversion from byte, ushort, or char to uint. Otherwise you must use a cast. For example, if you have a long variable, myLong, the following assignment statement will produce a compilation error without a cast:

long myLong = 22;
uint myUint = myLong;        // Error: no implicit conversion from long
uint myUint = (uint)myLong;  // OK: explicit conversion

Notice also that there is no implicit conversion from floating-point types to uint. For example, the following statement generates a compiler error unless an explicit cast is used:

uint x = 3.0;         // Error: no implicit conversion from double
uint y = (uint)3.0;   // OK: explicit conversion

For information on arithmetic expressions with mixed floating-point types and integral types, see float and double.

For more information on implicit numeric conversion rules, see the Implicit Numeric Conversions Table.

See Also

C# Keywords | Integral Types Table | Built-in Types Table | Implicit Numeric Conversions Table | Explicit Numeric Conversions Table | UInt32 Structure

Show:
© 2014 Microsoft