C# byte keyword: Here, we will find out about the byte keyword in C#, what is byte keyword, how to utilize it in C#?
C# byte keyword
In C#, byte is a keyword which is utilized to proclaim a variable that can store an unsigned incentive between 0 to 255.
byte keyword is a nom de plume of System.Byte.
It possesses 1 byte (8 bits) in the memory.
Syntax:
byte variable_name = value;
It can store an incentive between 0 to 255.
C# code to show example of byte keyword
Here, we are pronouncing a byte variable num, instating it with the worth 120 and printing its worth, type, and size of a byte type variable.
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//byte variable declaration
byte num = 120;
//printing value
Console.WriteLine("num: " + num);
//printing type of variable
Console.WriteLine("Type of num: " + num.GetType());
//printing size of a bool
Console.WriteLine("Size of a byte variable: " + sizeof(byte));
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output:
num: 120
Type of num: System.Byte
Size of a byte variable: 1