Char.GetHashCode() Method with Examples in C#

CsharpServer Side ProgrammingProgramming

<p>The Char.GetHashCode() method in C# is used to return the hash code for the current instance.</p><h2>Syntax</h2><p>Following is the syntax &minus;</p><pre class="result notranslate">public override int GetHashCode ();</pre><h2>Example</h2><p>Let us now see an example to implement the Char.GetHashCode() method &minus;</p><!--<p><a href="" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a></p>--><pre class="prettyprint notranslate">using System; public class Demo { &nbsp; &nbsp;public static void Main(){ &nbsp; &nbsp; &nbsp; char val = &#39;H&#39;; &nbsp; &nbsp; &nbsp; bool res; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Hashcode for val = &quot;+val.GetHashCode()); &nbsp; &nbsp; &nbsp; res = val.Equals(&#39;d&#39;); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Return Value = &quot;+res); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Hashcode for val = 4718664 Return Value = False</pre><h2>Example</h2><p>Let us now see another example &minus;</p><!--<p><a href="" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a></p>--><pre class="prettyprint notranslate">using System; public class Demo { &nbsp; &nbsp;public static void Main(){ &nbsp; &nbsp; &nbsp; char val = &#39;m&#39;; &nbsp; &nbsp; &nbsp; bool res; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Hashcode for val = &quot;+val.GetHashCode()); &nbsp; &nbsp; &nbsp; res = val.Equals(&#39;m&#39;); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Return Value = &quot;+res); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Hashcode for val = 7143533 Return Value = True</pre>
raja
Updated on 12-Nov-2019 09:29:22

Advertisements