HashCode function in VB.NET

HashCode function used to convert a large amount of data into small size. It is used for data comparison tasks. It is used to increase the performance of large collection of data. HashCode represent numerical that is why it’s not easy to trace any original message data.
  • 7168
 

HashCode function used to convert a large amount of data into small size. It is used for data comparison tasks. It is used to increase the performance of large collection of data. HashCode represent numerical that is why it's not easy to trace any original message data.

2.gif

If you have two same string you will get the same Hash Code for both strings. If there is any change in any character you will get differ Hash Code. See the below code to know how Hash Code represent differ numerical value for any change in string. Hash Code become more popular in distributed system, mostly it is using to store password information. Hash Code save password in numerical value this is the reason it give more security of your system.

Code

Module
Module1
    Sub Main()
        Dim Num1 As String, Num2 As String, str1 As String, str2 As String = Nothing
        Num1 = "1"
        Num2 = "2"
        str1 = "Mark"
        str2 = "Merk"

        Console.WriteLine(Integer.Parse(Num1))
        Console.WriteLine(Num1.GetHashCode())

        Console.WriteLine(Integer.Parse(Num2))
        Console.WriteLine(Num2.GetHashCode())

        Console.WriteLine(str1)
        Console.WriteLine(str1.GetHashCode())
 

        Console.WriteLine(str2)
        Console.WriteLine(str2.GetHashCode())

        Console.ReadLine()
    End Sub
End Module

In this code str1 = "Mark" represent different Hash Code and str2 = "Merk" represent different Hash Code. See the second position of both string changed and output of both string also differ.

Output

1.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.