Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
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
Advertisements
