> ## 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# int

The `int` keyword in C# is a built-in integral numeric type that represents a 32-bit signed integer. It is a language alias for the .NET `System.Int32` struct. As a value type, an `int` is stored directly in memory where it is declared (typically the thread stack, or inline within a reference type on the managed heap), rather than being allocated as a separate object.

## Technical Specifications

* **Underlying .NET Type:** `System.Int32`
* **Memory Size:** 32 bits (4 bytes)
* **Binary Representation:** Two's complement
* **Minimum Value:** `-2,147,483,648` (`int.MinValue`)
* **Maximum Value:** `2,147,483,647` (`int.MaxValue`)
* **Default Value:** `0`

## Syntax and Literals

The `int` type supports decimal, hexadecimal, and binary literals. Digit separators (`_`) can be used to improve readability. No type suffix is required for an `int` literal, as C# defaults to `int` for whole numbers within the 32-bit range.

```csharp theme={"dark"}
// Standard decimal literal
int decimalValue = 2147483647;

// Hexadecimal literal (prefix with 0x)
int hexValue = 0x7FFFFFFF;

// Binary literal (prefix with 0b)
int binaryValue = 0b_0111_1111_1111_1111_1111_1111_1111_1111;

// Default initialization
int defaultInt = default; // Evaluates to 0
```

## Type Conversions

Conversions between `int` and other numeric types are governed by the potential for data loss.

**Implicit Conversions**
C# allows implicit conversions from `int` to types that have a larger memory footprint or can accommodate the entire 32-bit signed range without truncation.

```csharp theme={"dark"}
int baseValue = 100;

long l = baseValue;     // 64-bit integer
float f = baseValue;    // 32-bit floating-point (precision loss possible, but no magnitude loss)
double d = baseValue;   // 64-bit floating-point
decimal m = baseValue;  // 128-bit precise decimal
```

**Explicit Conversions**
Converting to an `int` from a larger integral type or a floating-point type requires an explicit cast. Floating-point conversions truncate the fractional component toward zero.

```csharp theme={"dark"}
long largeValue = 2147483648L;
int castedInt = (int)largeValue; // Overflow occurs, evaluates to -2147483648

double floatingValue = 42.99;
int truncatedInt = (int)floatingValue; // Evaluates to 42
```

## Overflow Behavior

By default, arithmetic operations on `int` in C# execute in an `unchecked` context. If an operation exceeds `int.MaxValue` or falls below `int.MinValue`, it silently wraps around using two's complement arithmetic. This behavior can be modified using the `checked` keyword or compiler flags, which will instead throw an `OverflowException`.

```csharp theme={"dark"}
// Unchecked context (Default)
int max = int.MaxValue;
int overflow = max + 1; // Evaluates to -2147483648 (int.MinValue)

// Checked context
checked
{
    int maxVal = int.MaxValue;
    // int exceptionTrigger = maxVal + 1; // Throws System.OverflowException
}
```

<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>
