uint keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. uint is a keyword that is used to declare a variable which can store an integral type of value (unsigned integer) from the range of 0 to 4,294,967,295. It keyword is an alias of System.UInt32.

uint keyword occupies 4 bytes (32 bits) space in the memory.

Syntax:

uint variable_name = value;

Example:

Input: num: 67

Output: num2: 67
        Size of a uint variable: 4

Input: num = 24680

Output: Type of num1: System.UInt32
        num1: 24680
        Size of a uint variable: 4

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for uint keyword
using System;
using System.Text;
  
class GFG {
  
    static void Main(string[] args)
    {
        // variable declaration
        uint num2 = 67;
  
        // to print value
        Console.WriteLine("num2: " + num2);
  
        // to print size
        Console.WriteLine("Size of a uint variable: " + sizeof(uint));
    }
}

chevron_right


Output:

num2: 67
Size of a uint variable: 4

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for uint keyword
using System;
using System.Text;
  
namespace Geeks {
  
class GFG {
  
    static void Main(string[] args)
    {
        // variable declaration
        uint num1 = 24680;
  
        // to print type of variable
        Console.WriteLine("Type of num1: " + num1.GetType());
  
        // to print value
        Console.WriteLine("num1: " + num1);
  
        // to print size
        Console.WriteLine("Size of a uint variable: " + sizeof(uint));
  
        // to print minimum & maximum value of uint
        Console.WriteLine("Min value of uint: " + uint.MinValue);
        Console.WriteLine("Max value of uint: " + uint.MaxValue);
  
        // hit ENTER to exit
        Console.ReadLine();
    }
}
}

chevron_right


Output:

Type of num1: System.UInt32
num1: 24680
Size of a uint variable: 4
Min value of uint: 0
Max value of uint: 4294967295

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for uint keyword
using System;
using System.Text;
  
class GFG {
  
    static void Main(string[] args)
    {
        // variable declaration
        uint num2 = 4294967297;
  
        // to print type of variable
        Console.WriteLine("Type of num2: " + num2.GetType());
  
        // to print value
        Console.WriteLine("num2: " + num2);
  
        // to print size
        Console.WriteLine("Size of a uint variable: " + sizeof(uint));
    }
}

chevron_right


Error: When we input wrong integer and also input number beyond the range

Constant value `4294967297′ cannot be converted to a `uint’




My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.