In C#, a single byte is used to store 8-bits value. The byte and sbyte both are used for byte type of data.
byte : This Struct is used to represent 8-bit unsigned integers. The byte is an immutable value type and the range of Byte is from 0 to 255.
Example :
C#
using System;
using System.Text;
public class GFG{
static void Main( string [] args)
{
Console.WriteLine( "Minimum value of byte: " + byte .MinValue);
Console.WriteLine( "Maximum value of byte: " + byte .MaxValue);
}
}
|
Output:
Minimum value of byte: 0
Maximum value of byte: 255
sbyte : This Struct is used to represent 8-bit signed integers. The sbyte represents integers with values ranging from -128 to +127.
Example :
C#
using System;
using System.Text;
public class GFG{
static void Main( string [] args)
{
Console.WriteLine( "Minimum value of sbyte: " + sbyte .MinValue);
Console.WriteLine( "Maximum value of sbyte: " + sbyte .MaxValue);
}
}
|
Output:
Minimum value of sbyte: -128
Maximum value of sbyte: 127
Differences between byte and sbyte in C#
Sr.No
|
BYTE
|
SBYTE
|
1.
|
byte is used to represent 8-bit unsigned integers |
sbyte is used to represent 8-bit signed integers |
2.
|
byte stands for unsigned byte. |
sbyte stands for signed byte. |
3.
|
It can store positive bytes only. |
It can store negative and positive bytes. |
4.
|
It takes 8-bits space in the memory. |
It also takes 8-bits space in the memory. |
5.
|
The range of byte is from 0 to 255. |
The sbyte ranges from -128 to 127 |
6.
|
Syntax to declare the byte:
byte variable_name;
|
Syntax to declare the sbyte:
sbyte variable_name;
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
10 Nov, 2022
Like Article
Save Article