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

The `long` keyword in C# is a built-in value type that serves as an alias for the .NET `System.Int64` structure. It represents a 64-bit (8-byte) signed integer, utilizing two's complement representation to store numerical data.

## Technical Specifications

* **Underlying Type:** `System.Int64`
* **Memory Size:** 64 bits (8 bytes)
* **Sign Bit:** The most significant bit (MSB) denotes the sign (0 for positive, 1 for negative).
* **Minimum Value:** `-9,223,372,036,854,775,808` (`long.MinValue`)
* **Maximum Value:** `9,223,372,036,854,775,807` (`long.MaxValue`)
* **Default Value:** `0L`

## Syntax and Literals

By default, the C# compiler treats numeric literals as `int` if the value falls within the 32-bit signed integer range. To explicitly instruct the compiler to treat a literal as a `long`, append the `L` or `l` suffix. The uppercase `L` is standard convention to prevent visual confusion with the digit `1`.

```csharp theme={"dark"}
// Standard declaration and initialization
long a = 100000;

// Explicit literal typing using the 'L' suffix
long b = 9223372036854775807L;

// Hexadecimal literal
long c = 0x7FFFFFFFFFFFFFFFL;

// Binary literal (C# 7.0+) with digit separators
long binLiteral = 0b_0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L;
```

## Type Conversions

Because `long` is a 64-bit type, it participates in specific implicit and explicit conversion rules within the C# type system.

### Implicit Conversions

C# allows implicit conversions to `long` from any integral type with a smaller bit-width or an unsigned 32-bit type. A `long` can also be implicitly converted to floating-point types (`float`, `double`) and the `decimal` type. Conversion to floating-point types may result in a loss of precision, whereas conversion to `decimal` retains full precision.

```csharp theme={"dark"}
int intValue = 2147483647;
long implicitLong = intValue; // Implicit conversion from int to long

// Implicit conversion to floating-point types
float fValue = implicitLong;        // Compiles, but may lose precision
double doubleValue = implicitLong;  // Compiles, but may lose precision

// Implicit conversion to the decimal type
decimal decimalValue = implicitLong; // Compiles, no precision lost
```

### Explicit Conversions (Casting)

Conversions from types that exceed the maximum value of `long` (like `ulong`), or from floating-point and `decimal` types (which truncate the fractional part), require an explicit cast.

```csharp theme={"dark"}
ulong unsignedLong = 9223372036854775808ul;
long castedLong = (long)unsignedLong; // Explicit cast required

double fractionalDouble = 1234.56;
long truncatedLong = (long)fractionalDouble; // Evaluates to 1234
```

## Memory Layout

In memory, a `long` is stored as a contiguous 64-bit block. The size of the type can be evaluated at compile-time using the `sizeof` operator, which yields a constant value and does not require an `unsafe` context for built-in types.

```csharp theme={"dark"}
int size = sizeof(long); // Evaluates to 8
```

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