Last Updated : 11 Jul, 2025
In C#, Byte 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. This class allows us to create Byte data types and we can perform mathematical and bitwise operations on them like addition, subtraction, multiplication, division, XOR, AND etc.
FieldsExample:
C#
// C# program to illustrate MaxValue and MinValue fields in Byte
using System;
public class Geeks
{
static public void Main()
{
// Display the minimum and maximum value of Byte
Console.WriteLine("The minimum value of Byte: {0}"
, Byte.MinValue);
Console.WriteLine("The maximum value of Byte: {0}"
, Byte.MaxValue);
}
}
The minimum value of Byte: 0 The maximum value of Byte: 255Methods
Method
Description
Compares the current instance to a specified object and returns a sign of their relative values.
Compares this instance to a specified 8-bit unsigned integer and returns an indication of their relative values.To get a value which indicates whether the current instance is equal to a specified object or not.
Returns a value indicating whether this instance and a specified Byte object represent the same value.Returns the hash code for this instance.
Returns the TypeCode for value type Byte.Parse()
Converts the string representation of a number to its Byte equivalent.
Converts the value of the current Byte object to its equivalent string representation.TryParse()
Tries to convert the string representation of a number to its Byte equivalent, and returns a value that indicates whether the conversion succeeded.
BitConverter.GetBytes(Byte)
Converts a Byte value into a byte array.
Convert.ToByte(Object)
Converts an object to a byte, if possible.
Example: Using CompareTo(Byte)
C#
// C# program to illustrate the CompareTo(Byte) method
using System;
public class Geeks
{
static public void Main()
{
// Byte values for comparison
byte val1 = 32;
byte val2 = 40;
byte val3 = 10;
// Display the comparison using
// CompareTo(Byte) method
Console.WriteLine("Comparison 1: {0}"
, val1.CompareTo(val2));
Console.WriteLine("Comparison 2: {0}"
, val2.CompareTo(val3));
Console.WriteLine("Comparison 3: {0}"
, val3.CompareTo(val3));
Console.WriteLine("Comparison 4: {0}"
, val1.CompareTo(val3));
}
}
Comparison 1: -8 Comparison 2: 30 Comparison 3: 0 Comparison 4: 22
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4