×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# byte Keyword with Example

In this tutorial, we will learn about the byte keyword in C# (with Example), what is byte keyword, how to use it in C#? By IncludeHelp Last updated : April 04, 2023

C# byte Keyword

In C#, byte is a keyword which is used to declare a variable that can store an unsigned value between 0 to 255. byte keyword is an alias of System.Byte.

It occupies 1 byte (8 bits) in the memory.

Syntax

byte variable_name = value;

It can store value between 0 to 255.

Example of byte keyword in C#

Here, we are declaring a byte variable num, initializing it with the value 120 and printing its value, 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

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.