UInt64.MaxValue Field in C# with Examples

CsharpServer Side ProgrammingProgramming

<p>The UInt64.MaxValue field in C# represents the maximum value of the 64-bit unsigned integer.</p><h2>Syntax</h2><p>Following is the syntax &minus;</p><pre class="result notranslate">public const ulong MaxValue = 18446744073709551615;</pre><h2>Example</h2><p>Let us now see an example to implement the UInt64.MaxValue field &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; ulong val1 = 879879879; &nbsp; &nbsp; &nbsp; ulong val2 = 464556565; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Value1 = &quot;+val1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Value2 = &quot;+val2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode for value1 = &quot;+val1.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode for value2 = &quot;+val2.GetHashCode()); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Are they equal? = &quot;+(val1.Equals(val2))); &nbsp; &nbsp; &nbsp; TypeCode type1 = val1.GetTypeCode(); &nbsp; &nbsp; &nbsp; TypeCode type2 = val2.GetTypeCode(); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;TypeCode for val1 = &quot;+type1); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;TypeCode for val2 = &quot;+type2); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Maximum Value = &quot;+ UInt64.MaxValue); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Value1 = 879879879 Value2 = 464556565 HashCode for value1 = 879879879 HashCode for value2 = 464556565 Are they equal? = False TypeCode for val1 = UInt64 TypeCode for val2 = UInt64 Maximum Value = 18446744073709551615</pre><h2>Example</h2><p>Let us now see another example to implement the UInt64.MaxValue 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; ulong[]val = {8998, 899898778, 878787878}; &nbsp; &nbsp; &nbsp; ulong res; &nbsp; &nbsp; &nbsp; foreach(ulong a in val){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(a &gt;= UInt64.MinValue &amp;&amp; a &lt;= UInt64.MaxValue){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = Convert.ToUInt64(a); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Converted: &quot;+res); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Not Possible&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Converted: 8998 Converted: 899898778 Converted: 878787878</pre>
raja
Updated on 12-Nov-2019 10:34:39

Advertisements