Home » C#.Net

ushort keyword in C#

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

C# ushort keyword

In C#, ushort is a keyword which is used to declare a variable that can store an unsigned integer value between the range of 0 to 65,535. ushort keyword is an alias of System.UInt16.

It occupies 2 bytes (16 bits) space in the memory.

Syntax:

    ushort variable_name = value;

C# code to demonstrate example of ushort keyword

Here, we are declaring an ushort variable num, initializing it with the value 12345 and printing its value, type and size of an ushort type variable.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //variable declaration
            ushort num = 12345;

            //printing value
            Console.WriteLine("num: " + num);
            //printing type of variable
            Console.WriteLine("Type of num: " + num.GetType());
            //printing size
            Console.WriteLine("Size of a ushort variable: " + sizeof(ushort));
            //printing minimum & maximum value of ushort
            Console.WriteLine("Min value of ushort: " + ushort.MinValue);
            Console.WriteLine("Max value of ushort: " + ushort.MaxValue);

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

num: 12345
Type of num: System.UInt16
Size of a ushort variable: 2
Min value of ushort: 0
Max value of ushort: 65535
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




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.