Skip to content
Related Articles

Related Articles

C# | UInt64 Struct
  • Last Updated : 01 May, 2019

In C#, UInt64 struct is used to represent 64-bit unsigned integers(also termed as the ulong data type) starting from range 0 to 18,446,744,073,709,551,615. It also provides different types of methods to compare instances of this type, convert the value of an instance to its String representation, convert the String representation of a number to an instance of this type, etc. This struct is defined under System namespace. UInt64 struct inherits the ValueType class which inherits the Object class.

Fields

FieldDescription
MaxValueRepresents the largest possible value of UInt64. This field is constant.
MinValueRepresents the smallest possible value of UInt64. This field is constant.

Example:




// C# program to illustrate the 
// fields of UInt64 struct
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
  
        // Unsigned 64-bit integer
        ulong val = 18446744073709551615;
  
        // Checking the unsigned integer
        if (val.Equals(UInt64.MinValue)) 
        {
            Console.WriteLine("Equal to MinValue!");
        }
  
        else if (val.Equals(UInt64.MaxValue)) 
        {
            Console.WriteLine("Equal to MaxValue!");
        }
  
        else 
        {
            Console.WriteLine("Not Equal!");
        }
    }
}
Output:
Equal to MaxValue!

Methods

MethodDescription
CompareTo()Compares the current instance to a specified object or UInt64 and returns an indication of their relative values.
Equals()Returns a value which shows whether the current instance is equal to a specified object or UInt64.
GetHashCode()Returns the hash code for the current instance.
GetTypeCode()Returns the TypeCode for value type UInt64.
Parse()Converts the string representation of a number to its 64-bit unsigned integer equivalent.
ToString()Converts the numeric value of the current instance to its equivalent string representation.
TryParse()Tries to convert the string representation of a number to its 64-bit unsigned integer equivalent. A return value indicates whether the conversion succeeded or failed.

Example:






// C# program to illustrate how to get the 
// hash code of the 64-bit Unsigned integer
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
  
        // UInt64 variable
        ulong myval = 3654121225155;
  
        // Get the hash code
        // Using GetHashCode Method
        int res = myval.GetHashCode();
  
        Console.WriteLine("The hash code of myval is: {0}", res);
    }
}
Output:
The hash code of myval is: -895944559

Reference:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :