sbyte keyword in C#

C# sbyte keyword: Here, we will find out about the sbyte keyword in C#, what is sbyte keyword, how to utilize it in C#?

C# sbyte keyword

In C#, sbyte is a keyword which is utilized to pronounce a variable that can store a marked an incentive between the scope of – 128 to +127. sbyte keyword is an assumed name of System.SByte.

It possesses 1 byte (8 bits) in the memory.

Syntax:

    sbyte variable_name = value;

It can store the incentive between the scope of – 128 to +127.

C# code to show an example of sbyte keyword:

Here, we are pronouncing a sbyte variable num, introducing it with the worth – 120 and printing its worth, 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

Leave a Comment

error: Alert: Content is protected!!