Last Updated : 11 Jul, 2025
In C#, the Int64 struct represents a 64-bit signed integer and is commonly used as the long
data type. It belongs to the System namespace and provides various methods to perform operations like mathematical computations, parsing, and type conversion. The Int64 struct inherits from ValueType, which in turn inherits from Object.
Example: Using MaxValue and MinValue Fields
C#
// C# program to demonstrate
// MaxValue and MinValue fields
using System;
class Geeks
{
static public void Main()
{
// Declaring and initializing Int64 values
long v1 = 89;
long v2 = 50;
long v3 = 10;
Console.WriteLine("Value 1: {0}", v1);
Console.WriteLine("Value 2: {0}", v2);
Console.WriteLine("Value 3: {0}", v3);
// Displaying MaxValue and MinValue
Console.WriteLine("Maximum Value: {0}"
, long.MaxValue);
Console.WriteLine("Minimum Value: {0}"
, long.MinValue);
}
}
Value 1: 89 Value 2: 50 Value 3: 10 Maximum Value: 9223372036854775807 Minimum Value: -9223372036854775808Methods 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: Using Equals() Method
C#
// C# program to demonstrate the Int64.Equals() method
using System;
class Geeks
{
public static void Main()
{
// Declaring and initializing values
long v1 = 45643212342;
long v2 = 543256344233;
// Using Equals() method
bool status = v1.Equals(v2);
if (status)
Console.WriteLine("{0} is equal to {1}", v1, v2);
else
Console.WriteLine("{0} is not equal to {1}", v1, v2);
}
}
45643212342 is not equal to 543256344233
Example 2: Using GetTypeCode() Method
C#
// C# program to illustrate GetTypeCode() method
using System;
class Geeks
{
static public void Main()
{
// Declaring an Int64 value
long value = 45789478123;
// Getting the type code
// using GetTypeCode() method
TypeCode res = value.GetTypeCode();
// Displaying the TypeCode
Console.WriteLine("TypeCode for Int64 is: {0}", res);
}
}
TypeCode for Int64 is: Int64Bitwise Operations with Int64
Example:
C#
// C# program to demonstrate bitwise operations on Int64
using System;
class Geeks
{
static void Main()
{
long a = 5;
long b = 3;
// Performing bitwise operations
Console.WriteLine("Bitwise AND (a & b): "
+ (a & b));
Console.WriteLine("Bitwise OR (a | b): "
+ (a | b));
Console.WriteLine("Bitwise XOR (a ^ b): "
+ (a ^ b));
Console.WriteLine("Bitwise NOT (~a): "
+ (~a));
}
}
Bitwise AND (a & b): 1 Bitwise OR (a | b): 7 Bitwise XOR (a ^ b): 6 Bitwise NOT (~a): -6
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4