Convert.ToSByte() chuyển đổi giá trị thành số nguyên 8-bit signed (sbyte, -128 đến 127). Làm tròn Banker's Rounding.
Ví dụ minh họa
using System;
public class Demo
{
public static void Main()
{
double doubleNum = -19.9;
sbyte res = Convert.ToSByte(doubleNum);
Console.WriteLine("Đã chuyển {0} thành {1}", doubleNum, res);
}
}
Kết quả đầu ra
Đã chuyển -19.9 thành -20
Lưu ý: -19.9 làm tròn thành -20 (Banker's Rounding). Nếu giá trị ngoài phạm vi [-128, 127] sẽ ném OverflowException.