Open In App

C# | Int 64 Struct

Improve
Improve
Like Article
Like
Save
Share
Report

In C#, Int64 Struct is used to represent 64-bit signed integer(also termed as long data type) starting from range -9,223,372,036,854,775,808 to +9, 223,372,036,854,775,807. It provides different types of method to perform various operations. A user can perform the mathematical operation like addition, subtraction, multiplication, etc. on Int64 type. It supports bitwise operations like AND, OR, XOR, etc. It provides full support for standard and custom numeric format strings. The user can also call the methods of Convert and Math class to perform operations on Int64 value. Int64 struct inherits the ValueType class which inherits the Object class.

Fields

Fields Description
MaxValue This field is used to represent the largest possible value of an Int64. This field is constant.
MinValue This field is used to represent the smallest possible value of an Int64. This field is constant.

Example 1:




// C# program to illustrate the 
// MaxValue and MinValue field
using System;
  
class GFG {
  
    // Main method
    static public void Main()
    {
        Int64 var1 = 89;
        Int64 var2 = 50;
        Int64 var3 = 10;
  
        // Get the Maximum and Minimum value of 
        // Int64 type Using MaxValue and 
        // MinValue field
        Console.WriteLine("Value 1: {0}", var1);
        Console.WriteLine("Value 2: {0}", var2);
        Console.WriteLine("Value 3: {0}", var3);
  
        Console.WriteLine("Maximum Value: {0}",
                               Int64.MaxValue);
  
        Console.WriteLine("Minimum Value: {0}",
                               Int64.MinValue);
    }
}


Output:

Value 1: 89
Value 2: 50
Value 3: 10
Maximum Value: 9223372036854775807
Minimum Value: -9223372036854775808

Methods

Method Description
CompareTo() This method is used to compare this instance to a specified object or Int64 and returns an indication of their relative values.
Equals() This method is used to return a value indicating whether this instance is equal to a specified object or Int64.
GetHashCode() This method is used to return the hash code for this instance.
GetTypeCode() This method is used to return the TypeCode for value type Int64.
Parse() This method is used to convert the string representation of a number to its 64-bit signed integer equivalent.
ToString() This method is used to convert the numeric value of this instance to its equivalent string representation.
TryParse() This method is used to convert the string representation of a number to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded or failed.

Example 1:




// C# program to demonstrate the 
// Int64.Equals(Int64) Method 
using System; 
using System.Globalization; 
    
class GFG { 
    
    // Main Method 
    public static void Main() 
    
        // Declaring and initializing value1 
        long value1 = 45643212342; 
    
        // Declaring and initializing value2 
        long value2 = 543256344233; 
    
        // using Equals(Int64) method 
        bool status = value1.Equals(value2); 
    
        // checking the status 
        if (status) 
            Console.WriteLine("{0} is equal to {1}"
                                    value1, value2); 
        else
            Console.WriteLine("{0} is not equal to {1}"
                                        value1, value2); 
    


Output:

45643212342 is not equal to 543256344233

Example 2:




// C# program to illustrate the 
// Int64.GetTypeCode() Method 
using System; 
    
class GFG { 
    
    // Main Method 
    public static void Main() 
    
    
        // Taking long value 
        // i.e. Int64 
        long val = 45789478123; 
    
        // Getting the typecode for Int64 
        // using GetTypeCode() method 
        TypeCode result = val.GetTypeCode(); 
    
        // Display the TypeCode  
        Console.WriteLine("TypeCode for Int64 is: {0}"
                                               result); 
    


Output:

TypeCode for Int64 is: Int64

Reference:



Last Updated : 02 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads