
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Byte Struct in C#
Byte Struct in C# represents an 8-bit unsigned integer. Following are the fields −
Sr.no | Field & Description |
---|---|
1 | MaxValue Represents the largest possible value of a Byte. This field is constant. |
2 | MinValue Represents the smallest possible value of a Byte. This field is constant. |
Following are some of the methods −
Sr.no | Field & Description |
---|---|
1 | CompareTo(Byte) Compares this instance to a specified 8-bit unsigned integer and returns an indication of their relative values. |
2 | CompareTo(Object) Compares this instance to a specified object and returns an indication of their relative values. |
3 | Equals(Byte) Returns a value indicating whether this instance and a specified Byte object represent the same value. |
4 | Equals(Object) Returns a value indicating whether this instance is equal to a specified object. |
5 | GetHashCode() Returns the hash code for this instance. |
6 | GetTypeCode(). Returns the TypeCode for value type Byte. |
Example
using System; public class Demo { public static void Main() { string str = "186"; try { byte val = Byte.Parse(str); Console.WriteLine(val); } catch (OverflowException) { Console.WriteLine("Out of range of a byte.", str); } catch (FormatException) { Console.WriteLine("Out of range of a byte.", str); } } }
Output
This will produce the following output −
186
Example
Let us see another example −
using System; public class Demo { public static void Main() { byte[] arr = { 0, 10, 50, 90, 100, 150 }; foreach (byte b in arr) { Console.Write(" ", b.ToString()); Console.Write(b.ToString("D4") + " "); Console.WriteLine(b.ToString("X4")); } } }
Output
This will produce the following output −
0000 0000 0010 000A 0050 0032 0090 005A 0100 0064 0150 0096
- Related Articles
- UInt16 Struct in C#
- UInt32 Struct in C#
- Char Struct in C#
- UInt64 Struct in C#
- Decimal Struct in C#
- C# Int16 Struct
- C# Int32 Struct
- Int 64 Struct in C#
- Difference between 'struct' and 'typedef struct' in C++?
- C/C++ Struct vs Class
- Operations on struct variables in C
- Difference between 'struct' and 'typedef struct' in C++ program?
- Find max in struct array using C++.
- Byte.CompareTo(Byte) Method in C#
- Byte.Equals(Byte) Method in C#

Advertisements