ulong keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. ulong is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 18,446,744,073,709,551,615. It is an alias of System.UInt64.

ulong keyword occupies 8 bytes (64 bits) space in the memory.

Syntax:

ulong variable_name = value;

Example:

Input: num: 223

Output: num: 223
        Size of a ulong variable: 8

Input: num = 0

Output: Type of num: System.UInt64
        num: 0
        Size of a ulong variable: 8

Note:



  • If we input number beyond the range, it shows error-
    Integral constant is too large
  • If we input wrong value for eg. -34, it shows error-
    Constant value `-34' cannot be converted to a `ulong'
Example 1:
filter_none
edit close
play_arrow
link brightness_4 code
// C# program for ulong keyword
using System;
using System.Text;
  
class Prog {
  
    static void Main(string[] args)
    {
        // variable declaration
        ulong num = 223;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a ulong variable: " + sizeof(ulong));
    }
}
chevron_right

Output:

num: 223
Size of a ulong variable: 8

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for ulong keyword
using System;
using System.Text;
  
namespace Test {
  
class Prog {
  
    static void Main(string[] args)
    {
        // variable declaration
        ulong num = 0;
  
        // to print type of variable
        Console.WriteLine("Type of num: " + num.GetType());
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a ulong variable: " + sizeof(ulong));
  
        // to print 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();
    }
}
}

chevron_right


Output:

Type of num: System.UInt64
num: 0
Size of a ulong variable: 8
Min value of ulong: 0
Max value of ulong: 18446744073709551615



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.