uint keyword in C#
Last Updated :
22 Jun, 2020
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:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
uint num2 = 67;
Console.WriteLine( "num2: " + num2);
Console.WriteLine( "Size of a uint variable: " + sizeof ( uint ));
}
}
|
Output:
num2: 67
Size of a uint variable: 4
Example 2:
using System;
using System.Text;
namespace Geeks {
class GFG {
static void Main( string [] args)
{
uint num1 = 24680;
Console.WriteLine( "Type of num1: " + num1.GetType());
Console.WriteLine( "num1: " + num1);
Console.WriteLine( "Size of a uint variable: " + sizeof ( uint ));
Console.WriteLine( "Min value of uint: " + uint .MinValue);
Console.WriteLine( "Max value of uint: " + uint .MaxValue);
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:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
uint num2 = 4294967297;
Console.WriteLine( "Type of num2: " + num2.GetType());
Console.WriteLine( "num2: " + num2);
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’
Share your thoughts in the comments
Please Login to comment...