
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 −
Field | Description |
---|---|
MaxValue | Represents the largest possible value of an Int64. This field is constant. |
MinValue | Represents the smallest possible value of an Int64. This field is constant. |
Following are some of the methods −
Field | Description |
---|---|
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 −
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 −
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 −
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 −
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
- Related Articles
- UInt16 Struct in C#
- UInt32 Struct in C#
- Char Struct in C#
- Byte Struct in C#
- UInt64 Struct in C#
- Decimal Struct in C#
- C# Int16 Struct
- C# Int32 Struct
- Difference between 'struct' and 'typedef struct' in C++?
- C/C++ Struct vs Class
- Operations on struct variables in C
- Difference between 'struct' and 'typedef struct' in C++ program?
- Difference between const int*, const int * const, and int const * in C/C++?
- Find max in struct array using C++.
- Difference between const int*, const int * const, and int const * in C
