
- 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
Int64.GetHashCode Method in C# with Examples
The Int64.GetHashCode() method in C# is used to return the hash code for this instance.
Syntax
Following is the syntax −
public override int GetHashCode ();
Example
Let us now see an example to implement the Int64.GetHashCode() method −
using System; public class Demo { public static void Main(){ long val1 = 8768768768; long val2 = 7889765555; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode()); } }
Output
This will produce the following output −
Value1 = 8768768768 Value2 = 7889765555 Are they equal? = False Value1 (HashCode) = 178834178 Value2 (HashCode) = -700169038
Example
Let us now see another example to implement the Int64.GetHashCode() method −
using System; public class Demo { public static void Main(){ long val1 = 0; long val2 = Int64.MaxValue; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode()); } }
Output
This will produce the following output −
Value1 = 0 Value2 = 9223372036854775807 Are they equal? = False Value1 (HashCode) = 0 Value2 (HashCode) = -2147483648
- Related Articles
- UInt16.GetHashCode() Method in C# with Examples
- UInt64.GetHashCode() Method in C# with Examples
- Int16.GetHashCode() Method in C# with Examples
- Int32.GetHashCode Method in C# with Examples
- UInt32.GetHashCode() Method in C# with Examples
- Int64.CompareTo Method in C# with Examples
- Int64.Equals Method in C# with Examples
- Int64.GetTypeCode Method in C# with Examples
- Int64.MaxValue Field in C# with Examples
- Int64.MinValue Field in C# with Examples
- Int64.ToString() Method in C#
- MathF.Tan() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
- MathF.Truncate() Method in C# with Examples
- MathF.Sin() Method in C# with Examples

Advertisements