Home »
C# Tutorial
C# sbyte Keyword with Example
In this tutorial, we will learn about the sbyte Keyword in C# (with Example), what is sbyte keyword, how to use it in C#?
Last updated : April 04, 2023
C# sbyte Keyword
In C#, sbyte is a keyword which is used to declare a variable that can store a signed value between the range of -128 to +127. sbyte keyword is an alias of System.SByte.
It occupies 1 byte (8 bits) in the memory.
Syntax
sbyte variable_name = value;
It can store the value between the range of -128 to +127.
Example of sbyte keyword in C#
Here, we are declaring a sbyte variable num, initializing it with the value -120 and printing its value, type and size of a sbyte type variable.
using System;
using System.Text;
namespace ConsoleApplication3 {
class Program {
static void Main(string[] args) {
//char variable declaration
sbyte num = -120;
//printing value
Console.WriteLine("num: " + num);
//printing type of variable
Console.WriteLine("Type of num: " + num.GetType());
//printing size of a decimal
Console.WriteLine("Size of a sbyte variable: " + sizeof(sbyte));
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
num: -120
Type of num: System.SByte
Size of a sbyte variable: 1