ushort keyword in C#
Last Updated :
22 Jun, 2020
Keywords are the words in a language that are used for some internal process or represent some predefined actions. ushort is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 65,535. It is an alias of System.UInt16.
Syntax:
ushort variable_name = value;
ushort keyword occupies 2 bytes (16 bits) space in the memory.
Example:
Input: num: 5
Output: num: 5
Size of a ushort variable: 2
Input: num = 8765
Output: num: 8765
Type of num: System.UInt16
Size of a ushort variable: 2
Example 1:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
ushort num = 5;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a ushort variable: " + sizeof ( ushort ));
}
}
|
Output:
num: 5
Size of a ushort variable: 2
Example 2:
using System;
using System.Text;
namespace Test {
class GFG {
static void Main( string [] args)
{
ushort num = 8765;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Type of num: " + num.GetType());
Console.WriteLine( "Size of a ushort variable: " + sizeof ( ushort ));
Console.WriteLine( "Min value of ushort: " + ushort .MinValue);
Console.WriteLine( "Max value of ushort: " + ushort .MaxValue);
}
}
}
|
Output:
num: 8765
Type of num: System.UInt16
Size of a ushort variable: 2
Min value of ushort: 0
Max value of ushort: 65535
Share your thoughts in the comments
Please Login to comment...