Home » C#.Net

byte keyword in C#

C# byte keyword: Here, we are going to learn about the byte keyword in C#, what is byte keyword, how to use it in C#?
Submitted by IncludeHelp, on March 06, 2019

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.

C# code to demonstrate example of byte keyword

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




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.