Implicit conversion from Int16 to Decimal in C#

CsharpProgrammingServer Side Programming

The short type represents a 16-bit signed integer i.e. Int16.

To implicitly convert a 16-bit signed integer to a Decimal, firstly set a short value.

short val = -32768;

To convert short to decimal, assign the value.

dec = val;

Let us see another example.

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      short val = -32768;
      decimal dec;
      Console.WriteLine("Implicit conversion from Int16 to Decimal");
      dec = val;
      Console.WriteLine("Decimal : "+dec);
   }
}

Output

Implicit conversion from Int16 to Decimal
Decimal : -32768
raja
Published on 12-Sep-2018 09:26:14
Advertisements