C# UInt16 Struct Last Updated : 31 Jan, 2025 Comments Improve Suggest changes Like Article Like Report 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.UInt16 Range: It ranges from 0 to 65535.Operations: Converting the value of an instance to its string representation, converting a string representation of a number to an instance.This is useful when the need to store unsigned values does not allocate space for negative values, it provides a higher range.FieldsMaxValue: It represents the largest possible value of UInt16. This field is constant.MinValue: It represents the smallest possible value of UInt16. This field is constantExample: 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"); } } OutputNot equal MethodsMethodDescriptionCompareTo()Compares the current instance to a specified object or UInt16 and returns an indication of their relative values.Equals()Returns a value which shows whether the current instance is equal to a specified object or UInt16.GetHashCode()Returns the hash code for this instance.GetTypeCode()Returns the TypeCode for value type UInt16.Parse()Converts the string representation of a number to its 16-bit unsigned integer equivalentToString()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); } } OutputHash code of val: 545 Comment More infoAdvertise with us Next Article C# UInt16 Struct ankita_saini Follow Improve Article Tags : C# CSharp-UInt16-Struct Similar Reads C# UInt64 Struct In C#, the UInt64 struct represents a 64-bit unsigned integer, commonly referred to as the ulong data type. It is defined in the System namespace and provides various methods for mathematical computations, parsing, and type conversion. Since it is an unsigned type, it only holds non-negative values. 2 min read C# UInt32 Struct In C#, the UInt32 struct represents a 32-bit unsigned integer (commonly referred to as the uint data type). It is defined in the System namespace and provides various methods for mathematical computations, parsing, and type conversion. Because of it is an unsigned type, it only holds non-negative va 2 min read C# Byte Struct In C#, Byte Struct is used to represent 8-bit unsigned integers. The Byte is an immutable value type and the range of Byte is from 0 to 255. This class allows us to create Byte data types and we can perform mathematical and bitwise operations on them like addition, subtraction, multiplication, divis 2 min read C# Int16 Struct In C#, Int16 Struct defined under the System namespace represents a 16-bit signed integer also known as a short datatype etc. We can also call the methods of math class to perform mathematical operations. Int16 struct inherits the ValueType class which inherits the Object class. Characteristics are 3 min read C# Int32 Struct In C#, the Int32 struct represents a 32-bit signed integer and is commonly used as the int data type. It belongs to the System namespace and provides various methods to perform operations like mathematical computations, parsing, and type conversion. The Int32 struct inherits from ValueType, which in 3 min read Like