Convert.ToInt16(); Method in C#
This strategy is utilized to converts the specified data type to an equivalent 16-bit signed integer.
So let's see the example which demonstrates Convert.ToInt16 method as shown below.
using System;
namespace ToInt16_program
{
class program
{
static void Main(string[] args)
{
double f=12345.055;
/* converting double to specified int */
int value = Convert.ToInt16(f);
/* Display the converted float value */
Console.Write("Float value ="+f+"\n Converted to Int_16_bit={0} ", value,f);
Console.ReadKey();
}
}
}
Output
This strategy is utilized to converts the specified data type to an equivalent 16-bit signed integer.
So let's see the example which demonstrates Convert.ToInt16 method as shown below.
using System;
namespace ToInt16_program
{
class program
{
static void Main(string[] args)
{
double f=12345.055;
/* converting double to specified int */
int value = Convert.ToInt16(f);
/* Display the converted float value */
Console.Write("Float value ="+f+"\n Converted to Int_16_bit={0} ", value,f);
Console.ReadKey();
}
}
}
Output