C# ulong Keyword with Example

In this tutorial, we will learn about the ulong keyword in C# (with Example), what is ulong keyword, how to use it in C#? By IncludeHelp Last updated : April 04, 2023

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;

Example of ulong keyword in C#

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



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.