Decimal.GetTypeCode() Method in C# with Examples

CsharpServer Side ProgrammingProgramming

<p>The Decimal.GetTypeCode() method in C# is used to returns the TypeCode for value type Decimal.</p><h2>Syntax</h2><p>Following is the syntax &minus;</p><pre class="result notranslate">public TypeCode GetTypeCode ();</pre><h2>Example</h2><p>Let us now see an example to implement the Decimal.GetTypeCode() 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; Decimal val = Decimal.MaxValue; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Decimal Value = {0}&quot;, val); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode = {0}&quot;, (val.GetHashCode()) ); &nbsp; &nbsp; &nbsp; TypeCode type = val.GetTypeCode(); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;TypeCode = &quot;+type); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Decimal Value = 79228162514264337593543950335 HashCode = 1173356544 TypeCode = Decimal</pre><h2>Example</h2><p>Let us now see another example to implement the Decimal.GetTypeCode() 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; Decimal val = 3972.491M; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Decimal Value = {0}&quot;, val); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;HashCode = {0}&quot;, (val.GetHashCode()) ); &nbsp; &nbsp; &nbsp; TypeCode type = val.GetTypeCode(); &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;TypeCode = &quot;+type); &nbsp; &nbsp;} }</pre><h2>Output</h2><p>This will produce the following output &minus;</p><pre class="result notranslate">Decimal Value = 3972.491 HashCode = 620041307 TypeCode = Decimal</pre>
raja
Updated on 12-Nov-2019 09:22:17

Advertisements