
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
UInt16.MaxValue Field in C# with Examples
The UInt16.MaxValue field in C# represents the maximum value of the 16-bit unsigned integer.
Syntax
Following is the syntax −
public const ushort MaxValue = 65535;
Example
Let us now see an example to implement the UInt16.MaxValue field −
using System; public class Demo { public static void Main(){ ushort val1 = 23; ushort val2 = 0; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); Console.WriteLine("HashCode for value1 = "+val1.GetHashCode()); Console.WriteLine("HashCode for value2 = "+val2.GetHashCode()); Console.WriteLine("Are they equal? = "+(val1.Equals(val2))); TypeCode type1 = val1.GetTypeCode(); TypeCode type2 = val2.GetTypeCode(); Console.WriteLine("TypeCode for val1 = "+type1); Console.WriteLine("TypeCode for val2 = "+type2); Console.WriteLine("Maximum Value = "+ UInt16.MaxValue); } }
Output
This will produce the following output −
Value1 = 23 Value2 = 0 HashCode for value1 = 23 HashCode for value2 = 0 Are they equal? = False TypeCode for val1 = UInt16 TypeCode for val2 = UInt16 Maximum Value = 65535
Example
Let us now see another example to implement the UInt16.MaxValue method −
using System; public class Demo { public static void Main(){ ulong[]val = {8998, 899898778, 878787878}; ushort res; foreach(ulong a in val){ if(a >= UInt16.MinValue && a <= UInt16.MaxValue){ res = Convert.ToUInt16(a); Console.WriteLine("Converted: "+res); } else { Console.WriteLine("Not Possible"); } } } }
Output
This will produce the following output −
Converted: 8998 Not Possible Not Possible
- Related Articles
- UInt32.MaxValue Field in C# with Examples
- Int16.MaxValue Field in C# with Examples
- UInt64.MaxValue Field in C# with Examples
- Int32.MaxValue Field in C# with Examples
- Int64.MaxValue Field in C# with Examples
- UInt16.MinValue Field in C# with Examples
- UInt16.CompareTo() Method in C# with Examples
- UInt16.Equals Method in C# with Examples
- UInt16.GetHashCode() Method in C# with Examples
- UInt16.GetTypeCode() Method in C# with Examples
- UInt16.ToString Method in C# with Examples
- UInt32.MinValue Field in C# with Examples
- Int16.MinValue Field in C# with Examples
- UInt64.MinValue Field in C# with Examples
- Int32.MinValue Field in C# with Examples

Advertisements