> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# ushort

The `ushort` keyword in C# is an alias for the .NET `System.UInt16` structure. It represents a 16-bit (2-byte) unsigned integral value type used to store positive whole numbers and zero. Because it is unsigned, it cannot represent negative values, allocating all 16 bits strictly to the magnitude of the number.

## Technical Specifications

* **Underlying Type:** `System.UInt16`
* **Memory Size:** 16 bits (2 bytes)
* **Value Range:** `0` to `65,535` ($2^{16} - 1$)
* **Default Value:** `0`
* **CLS Compliance:** `ushort` is *not* Common Language Specification (CLS) compliant.

## Syntax and Initialization

C# does not have a dedicated literal suffix for the `ushort` type. Integer literals are treated as `int` by default, but the compiler will implicitly convert an `int` literal to a `ushort` during assignment if the value falls within the valid 16-bit unsigned range.

```csharp theme={"dark"}
// Standard initialization
ushort minValue = 0;
ushort maxValue = 65535;

// Using the underlying .NET struct constants
ushort min = System.UInt16.MinValue;
ushort max = System.UInt16.MaxValue;

// Hexadecimal and binary literals
ushort hexValue = 0xFFFF;      // 65535
ushort binaryValue = 0b_1010;  // 10
```

## Type Conversions

**Implicit Conversions**
A `ushort` can be implicitly converted to any numeric type that has a larger memory footprint or can accommodate its maximum value without data loss. Valid implicit conversion targets are: `int`, `uint`, `long`, `ulong`, `float`, `double`, and `decimal`.

```csharp theme={"dark"}
ushort baseValue = 42000;
int intValue = baseValue;       // Implicit conversion to 32-bit signed integer
float floatValue = baseValue;   // Implicit conversion to single-precision floating-point
```

**Explicit Conversions (Casting)**
Converting to a `ushort` from a larger integral type (e.g., `int`), a floating-point type, or a signed type (e.g., `short`) requires an explicit cast. This is enforced by the compiler because the source value might exceed the `ushort` upper bound of `65,535` or be less than `0`. Depending on the execution context (`checked` vs. `unchecked`), invalid conversions will either throw an `OverflowException` or result in silent bitwise truncation.

```csharp theme={"dark"}
int largeValue = 70000;
// ushort invalid = largeValue; // Compiler error: Cannot implicitly convert type 'int' to 'ushort'

// Explicit cast required. In an unchecked context, this results in data loss (truncation).
ushort truncatedValue = (ushort)largeValue; 

short signedValue = -5;
// Explicit cast required due to sign difference. Results in underflow if unchecked.
ushort castedFromSigned = (ushort)signedValue; 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
