sbyte Keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. SByte is a keyword that is used to declare a variable that can store a signed value between the range of -128 to +127. It is an alias of System.SByte.

SByte keyword occupies 1 byte (8 bits) in the memory.

Syntax:

sbyte variable_name = value;

SByte keyword can store the value from the range of -128 to +127.

Example:



Input: -109

Output: num: -109
        Size of a sbyte variable: 1

Input: 110

Output: Type of num: System.SByte
        num: 110
        Size of a sbyte variable: 1

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for sbyte keyword
using System;
using System.Text;
  
class GFG {
  
    static void Main(string[] args)
    {
        // char variable declaration
        sbyte num = -109;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size of a sbyte
        Console.WriteLine("Size of a sbyte variable: " + sizeof(sbyte));
    }
}

chevron_right


Output:

num: -109
Size of a sbyte variable: 1

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for sbyte keyword
using System;
using System.Text;
  
namespace geeks {
  
class GFG {
  
    static void Main(string[] args)
    {
        // char variable declaration
        sbyte num = 110;
  
        // to print type of variable
        Console.WriteLine("Type of num: " + num.GetType());
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size of sbyte 
        Console.WriteLine("Size of a sbyte variable: " + sizeof(sbyte));
  
        // hit ENTER to exit
        Console.ReadLine();
    }
}
}

chevron_right


Output:

Type of num: System.SByte
num: 110
Size of a sbyte variable: 1

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for sbyte keyword
using System;
using System.Text;
  
class GFG {
  
    static void Main(string[] args)
    {
        // char variable declaration
        sbyte num = -189;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size of a sbyte
        Console.WriteLine("Size of a sbyte variable: " + sizeof(sbyte));
    }
}

chevron_right


Error: When we enter number beyond the range from (-128-127).

Constant value `-189′ cannot be converted to a `sbyte’




My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.