
A uint is an unsigned integer. It is similar to int, but does not reserve space for the sign. Unsigned integers can be used in the place of signed integers in many programs. They help when you need to increase the bounds of a loop.
Int Type KeywordsSystem.UInt32 information uint.MinValue = 0 uint.MaxValue = 4294967295
This page shows the C# uint type, an unsigned integer. It provides an example program.

The uint type in the C# language is exactly the same as the System.UInt32 type in the System namespace, and was added to provide for clearer code in programs. You can use UInt32 instead if your include the System namespace with a using directive or use the fully qualified name "System.UInt32". This example shows some differences between uints and ints.
Example that uses uint type [C#]
using System;
class Program
{
static void Main()
{
// Declare example unsigned and signed integers.
uint value1 = 100;
int value2 = 100;
// Display values.
Console.WriteLine(value1);
Console.WriteLine(value2);
// Assign the maximum values.
uint max1 = uint.MaxValue;
int max2 = int.MaxValue;
// Display maximum values.
Console.WriteLine(max1);
Console.WriteLine(max2);
// Assign the minimum values.
uint min1 = uint.MinValue;
int min2 = int.MinValue;
// Write the minimum values.
Console.WriteLine(min1);
Console.WriteLine(min2);
// Write the types.
Console.WriteLine(typeof(uint));
Console.WriteLine(typeof(int));
}
}
Output
100
100
4294967295
2147483647
0
-2147483648
System.UInt32
System.Int32Initializing uint type. The uint value type in the example program is initialized in the exact same way as the int type. When your code that uses uint is executed in the runtime, it is allocated in the method's stack, which means no dynamic allocation in the heap is done. This is very efficient. Note that you must always assign uints that are local variables, so the compiler can prove no uninitialized memory on the stack is used. This process is called definite assignment analysis.
Definite Assignment AnalysisMaxValue property. The MaxValue field on the System.UInt32 type in the base class library is equal to 4294967295. This is invariant and will always be true. There is no advantage to hard-coding 4294967295 in your application, as using uint.MaxValue will actually result in the literal integer being substituted in your code.

MinValue property. The MinValue property on the System.UInt32 type is also a constant in the base class library. This field is always equal to zero; this is true because uints lack the sign bit that, when set, makes a number equal a negative value.
Const ExampleTypes of integers. The final part of the program displays the System.Type object for the two numeric types. The typeof keyword is not actually a function but is considered an operator in the C# language. All types in the language inherit from the object type, and the object type contains a type pointer that indicates its kind. The typeof operator accesses this pointer.

There exist some errors regarding the int and uint types in the C# language. If you try to assign an int variable in your program to a numeric literal that is too big, the C# compiler will give you a compile-time error. For example, try compiling the code "int value1 = 3000000000;". If you change the "int" type to "uint", your program will compile successfully.
Error 1 Cannot implicitly convert type 'uint' to 'int'. An explicit conversion exists (are you missing a cast?)

We looked at the unsigned integer type in the C# programming language, which is accessed with the uint keyword or the System.UInt32 type. We saw how uint values are used and what their maximum and minimum values are, and how you can access those values in your program. Finally, we noted the object model in the C# language and discussed a common error relating to the uint type.
Number Examples