Convert.ToSByte Method in C#


Convert a specified value to an 8-bit signed integer i.e. SByte.

It is a signed 8-bit integer data type which stores value between -128 to 127.

Let us see an example. We have a double variable.

double doubleNum = -19.9;

Now, let us convert it to SByte.

sbyte res;
res = Convert.ToSByte(doubleNum);

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      double doubleNum = -19.9;
      sbyte res;
      res = Convert.ToSByte(doubleNum);
      Console.WriteLine("Converted {0} to {1}", doubleNum, res);
   }
}

Output

Converted -19.9 to -20

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements