Convert.ToInt16 Method in C#


Convert a specified value to a 16-bit signed integer using the Convert.ToInt16 method in C#.

We have a double variable with a value initialized to it.

double doubleNum = 3.456;

Now, let us convert it to Int16 i.e. short.

short shortNum;
shortNum = Convert.ToInt16(doubleNum);

Here is the complete example −

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      double doubleNum = 3.456;
      short shortNum;
      shortNum = Convert.ToInt16(doubleNum);
      Console.WriteLine("Converted {0} to {1}", doubleNum, shortNum);
   }
}

Output

Converted 3.456 to 3

Updated on: 22-Jun-2020

560 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements