Last Updated : 11 Jul, 2025
In C#, the UInt16 struct, defined under the System namespace, represents a 16-bit unsigned integer, commonly referred to as the ushort data type. It does not support negative values and provides a range from 0 to 65,535. The UInt16 struct inherits the ValueType class, which further inherits the Object class.
Example:
C#
// C# program to illustrate the fields of UInt16 struct
using System;
class Geeks
{
static public void Main()
{
// Unsigned 16-bit integer
ushort val = 295;
// Checking the unsigned integer
if (val.Equals(UInt16.MinValue))
Console.WriteLine("Equal to MinValue..!");
else if (val.Equals(UInt16.MaxValue))
Console.WriteLine("Equal to MaxValue");
else
Console.WriteLine("Not equal");
}
}
Methods
Method
Description
Compares the current instance to a specified object or UInt16 and returns an indication of their relative values.
Returns a value which shows whether the current instance is equal to a specified object or UInt16.
Returns the hash code for this instance.
Returns the TypeCode for value type UInt16.
Parse()
Converts the string representation of a number to its 16-bit unsigned integer equivalent
Converts the numeric value of this instance to its equivalent string representation.TryParse()
Converts a number in string form to a 16-bit unsigned integer, indicating success or failure.Example: Using GetHashCode() Method
C#
// C# program to illustrate how to get the hash
// code of a 16-bit Unsigned integer
using System;
class Geeks
{
static public void Main()
{
// UInt16 variable
ushort val = 545;
// Get the hash code using GetHashCode Method
int res = val.GetHashCode();
Console.WriteLine("Hash code of val: {0}", res);
}
}
Hash code of val: 545
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4