sbyte Keyword in C#
Last Updated :
22 Jun, 2020
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:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
sbyte num = -109;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a sbyte variable: " + sizeof ( sbyte ));
}
}
|
Output:
num: -109
Size of a sbyte variable: 1
Example 2:
using System;
using System.Text;
namespace geeks {
class GFG {
static void Main( string [] args)
{
sbyte num = 110;
Console.WriteLine( "Type of num: " + num.GetType());
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a sbyte variable: " + sizeof ( sbyte ));
Console.ReadLine();
}
}
}
|
Output:
Type of num: System.SByte
num: 110
Size of a sbyte variable: 1
Example 3:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
sbyte num = -189;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a sbyte variable: " + sizeof ( sbyte ));
}
}
|
Error: When we enter number beyond the range from (-128-127).
Constant value `-189′ cannot be converted to a `sbyte’
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...