Home »
C#.Net
ulong keyword in C#
C# ulong keyword: Here, we are going to learn about the ulong keyword in C#, what is ulong keyword, how to use it in C#?
Submitted by IncludeHelp, on March 07, 2019
C# ulong keyword
In C#, ulong is a keyword which is used to declare a variable that can store an unsigned integer value between the range of 0 to 18,446,744,073,709,551,615. ulong keyword is an alias of System.UInt64.
It occupies 8 bytes (64 bits) space in the memory.
Syntax:
ulong variable_name = value;
C# code to demonstrate example of ulong keyword
Here, we are declaring an ulong variable num, initializing it with the value 12345 and printing its value, type and size of an ulong type variable.
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//variable declaration
ulong num = 12345;
//printing value
Console.WriteLine("num: " + num);
//printing type of variable
Console.WriteLine("Type of num: " + num.GetType());
//printing size
Console.WriteLine("Size of a ulong variable: " + sizeof(ulong));
//printing minimum & maximum value of ulong
Console.WriteLine("Min value of ulong: " + ulong.MinValue);
Console.WriteLine("Max value of ulong: " + ulong.MaxValue);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
num: 12345
Type of num: System.UInt64
Size of a ulong variable: 8
Min value of ulong: 0
Max value of ulong: 18446744073709551615