In C#, Convert.ToUInt16 returns a ushort—unsigned 16-bit integer from 0 to 65,535.
Negatives and values above 65535 throw OverflowException. Bad text throws FormatException.
This is a static member of System.Convert. You call it with the type name, such as Convert.ToUInt16(...). Convert is the everyday API for converting between common CLR types in C#.
Syntax
Convert text or numbers into a ushort.
C#
ushort a = Convert.ToUInt16("1000");
ushort b = Convert.ToUInt16(50);
ushort c = Convert.ToUInt16("FFFF", 16);
Call
What it does
Convert.ToUInt16("1000")
Decimal string → ushort.
Convert.ToUInt16("FFFF", 16)
Hex → 65535.
null → 0. Prefer ushort.TryParse for soft failure.
Library declarations
C#
public static ushort ToUInt16(string? value);
public static ushort ToUInt16(string? value, int fromBase);
public static ushort ToUInt16(int value);
Parameters
Parameter
Description
value
Required. Text or number to convert.
fromBase
Optional. 2, 8, 10, or 16.
Return Value
Return Value
Description
ushort
Unsigned 16-bit result.
C# Examples
Example 1 — Parse an Unsigned Short
Convert a decimal string to UInt16.
C#
using System;
class Program {
static void Main() {
ushort n = Convert.ToUInt16("500");
Console.WriteLine(n);
Console.WriteLine(n + 20);
}
}
Output
500
520
How It Works
Unsigned short. Result type is ushort.
500 fits. Inside 0…65535.
Add twenty. Ordinary integer math.
Null → 0. Convert remains null-friendly.
Example 2 — FFFF Hex Edge
Parse the maximum ushort via hex.
C#
using System;
class Program {
static void Main() {
ushort n = Convert.ToUInt16("FFFF", 16);
Console.WriteLine(n);
Console.WriteLine(Convert.ToUInt16("10", 2));
}
}
Output
65535
2
How It Works
FFFF. Hex max equals 65535.
Binary 10. Base 2 yields 2.
Edge success. Exactly max does not throw.
65536 fails. One more would overflow.
Example 3 — Reject Negatives
Show that negative ints overflow for ushort.
C#
using System;
class Program {
static void Main() {
try {
Console.WriteLine(Convert.ToUInt16(-1));
} catch (OverflowException) {
Console.WriteLine("unsigned only");
}
Console.WriteLine(Convert.ToUInt16(0));
}
}