

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the HashCode for the string in C#?
To get the HashCode for the string, the code is as follows, the code is as follows −
Example
using System; public class Demo { public static void Main(String[] args) { string str1 = "Akon"; string str2 = "Eminem"; Console.WriteLine("String 1 = "+str1); Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode()); Console.WriteLine("String 2 = "+str2); Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode()); Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2)); } }
Output
This will produce the following output −
String 1 = Akon HashCode of String 1 = 416613838 String 2 = Eminem HashCode of String 2 = 40371907 String 1 is equal to String 2: False
Example
Let us see another example −
using System; public class Demo { public static void Main(String[] args) { string str1 = "Imagine Dragons"; string str2 = "Imagine Dragons"; Console.WriteLine("String 1 = "+str1); Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode()); Console.WriteLine("String 2 = "+str2); Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode()); Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2)); } }
Output
This will produce the following output −
String 1 = Imagine Dragons HashCode of String 1 = -1546868095 String 2 = Imagine Dragons HashCode of String 2 = -1546868095 String 1 is equal to String 2: True
- Related Questions & Answers
- Get the HashCode for the current UInt64 instance in C#
- Get the HashCode for the current UInt32 instance in C#
- How to get the HashCode of the tuple in C#?
- The hashCode() method of CopyOnWriteArrayList method in Java
- The hashCode() method of AbstractList class in Java
- How to get the length of a string in Python?
- How to get the size of a string in Python?
- How to get the Length of a String in Java?
- How to get the length of a string in JavaScript?
- How to get the primitive value of string in Javascript?
- How to search for the exact string value in MySQL?
- How to get first 100 characters of the string in Python?
- How to get max alphabetical character from the string in Python?
- How to get min alphabetical character from the string in Python?
- What does the method hashCode(obj[] a) do in java?
Advertisements