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:
// 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 )); } } |
Output:
num2: 67 Size of a uint variable: 4
Example 2:
// 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(); } } } |
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:
// 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 )); } } |
Error: When we input wrong integer and also input number beyond the range
Constant value `4294967297′ cannot be converted to a `uint’