Convert.ToInt16 Method in C#

ProgrammingServer Side ProgrammingCsharp

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
raja
Published on 11-Sep-2018 12:37:54
Advertisements