Int 64 Struct in C#


The Int 64 struct represents a 64-bit signed integer. It is an immutable value type representing signed integers with values: negative 9,223,372,036,854,775,808 through positive 9,223,372,036,854,775,807.

Following are the fields of Int 64 −

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

Following are some of the methods −

FieldDescription
CompareTo(Int64)Compares this instance to a specified 64-bit signed integer and returns an indication of their relative values.
CompareTo(Object)Compares this instance to a specified object and returns an indication of their relative values.
Equals(Int64)Returns a value indicating whether this instance is equal to a specified Int64 value.
Equals(Object)Returns a value indicating whether this instance is equal to a specified object.
GetHashCode()Returns the hash code for this instance.
GetTypeCode()Returns the TypeCode for value type Int64.
Parse(String)Converts the string representation of a number to its 64-bit signed integer equivalent.
Parse(String, IFormatProvider)Converts the string representation of a number in a specified culture-specific format to its 64-bit signed integer equivalent.

Let us now see some examples of the methods −

The Int64.CompareTo() method in C# is used to compare this instance to a specified object or Int64 and returns an indication of their relative values.

Syntax

Following is the syntax −

public int CompareTo (long val);
public int CompareTo (object val);

Above, in the 1st syntax, the value val is an integer to compare. The val in the 2nd syntax is an object to compare.

Example

Let us now see an example to implement the Int64.CompareTo() method −

 Live Demo

using System;
public class Demo {
   public static void Main(){
      long val1 = 20;
      long val2 = 18;
      Console.WriteLine("Value 1 = "+val1);
      Console.WriteLine("Value 2 = "+val2);
      Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2));
   }
}

Output

This will produce the following output −

Value 1 = 20
Value 2 = 18
Return value (comparison) = 1

Example

Let us now see another example to implement the Int64.CompareTo() method −

 Live Demo

using System;
public class Demo {
   public static void Main(){
      long val1 = 20;
      object val2 = (long)20;
      Console.WriteLine("Value 1 = "+val1);
      Console.WriteLine("Value 2 = "+val2);
      Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2));
   }
}

Output

This will produce the following output −

Value 1 = 20
Value 2 = 20
Return value (comparison) = 0

The Int64.Equals() method in C# is used to return a value indicating whether this instance is equal to a specified object or Int64.

Syntax

Following is the syntax −

public bool Equals (long ob);
public override bool Equals (object ob);

Above, the parameter ob is an Int64 value to compare to this instance, whereas the parameter ob is an object to compare with this instance.

Example

Let us now see an example to implement the Int64.Equals() method −

 Live Demo

using System;
public class Demo {
   public static void Main(){
      long val1 = 150;
      long val2 = 240;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("Are they equal? = "+val1.Equals(val2));
   }
}

Output

This will produce the following output −

Value1 = 150
Value2 = 240
Are they equal? = False

Example

Let us now see another example to implement the Int64.Equals() method −

 Live Demo

using System;
public class Demo {
   public static void Main(){
      long val1 = 8768768768;
      long val2 = 8768768768;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("Are they equal? = "+val1.Equals(val2));
   }
}

Output

This will produce the following output −

Value1 = 8768768768
Value2 = 8768768768
Are they equal? = True
raja
Published on 03-Dec-2019 09:16:37
Advertisements