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

A class in C# is a user-defined reference type that serves as a blueprint for instantiating objects. It encapsulates state (data) and behavior (operations) into a single logical unit, forming the foundational structure of object-oriented programming in the .NET ecosystem. Because classes are reference types, their instances are allocated on the managed heap, and variables hold a memory address pointing to the object rather than the object's actual data. Memory reclamation is handled non-deterministically by the .NET Garbage Collector.

## Syntax Anatomy

The declaration of a class utilizes the `class` keyword, optionally preceded by access and class modifiers, and optionally followed by a base class and implemented interfaces.

```csharp theme={"dark"}
[access_modifier] [class_modifier] class ClassName : BaseClass, IInterface1, IInterface2
{
    // Member declarations
}
```

## Class Members

A class is composed of members that define its state and behavior.

* **Constants:** Immutable values evaluated at compile-time. They are implicitly static.
* **Fields:** Variables declared at the class scope. They represent the raw state of the object.
* **Properties:** Members that provide a flexible mechanism to read, write, or compute the value of a private field. They utilize `get`, `set`, or `init` accessors to enforce encapsulation.
* **Methods:** Functions defined within the class that execute specific behaviors or algorithms.
* **Constructors:** Special methods invoked automatically during object instantiation (via the `new` keyword) to initialize the object's state.
* **Events:** Members that enable a class or object to notify other classes or objects when something of interest occurs, typically backed by delegates.
* **Indexers:** Members that allow an object to be indexed in the same manner as an array using `this[]` syntax.
* **Operators:** Custom implementations of standard operators (e.g., `+`, `==`) for the class, defined using the `operator` keyword.
* **Nested Types:** Types (such as classes, structs, enums, or interfaces) declared entirely within the body of the class, typically used to encapsulate internal implementation details.
* **Finalizers (Destructors):** A special method (`~ClassName()`) invoked by the Garbage Collector to perform cleanup of unmanaged resources before the object's memory is reclaimed.

```csharp theme={"dark"}
using System;

public abstract class BaseProcessor
{
    public abstract void Execute();
}

public class DataProcessor : BaseProcessor, IDisposable
{
    // Constant
    public const int DefaultTimeoutMs = 5000;

    // Field
    private readonly int _bufferSize;

    // Property with auto-implemented accessors
    public string ProcessorId { get; init; }

    // Constructor
    public DataProcessor(int bufferSize, string processorId)
    {
        _bufferSize = bufferSize;
        ProcessorId = processorId;
    }

    // Method overriding base abstract method
    public override void Execute()
    {
        // Implementation
    }

    // Indexer
    public int this[int index]
    {
        get { return index * _bufferSize; }
    }

    // User-defined Operator
    public static DataProcessor operator +(DataProcessor a, DataProcessor b)
    {
        return new DataProcessor(a._bufferSize + b._bufferSize, $"{a.ProcessorId}_{b.ProcessorId}");
    }

    // Nested Type
    public class ProcessorState
    {
        public bool IsActive { get; set; }
    }

    // IDisposable implementation
    public void Dispose()
    {
        GC.SuppressFinalize(this);
    }
}
```

## Technical Characteristics

**Inheritance Rules**
C# enforces single class inheritance. A class can inherit from at most one direct base class. If no base class is explicitly declared, the class implicitly inherits from `System.Object`. While limited to a single base class, a class can implement an unlimited number of interfaces.

**Access Modifiers**
Classes and their members utilize access modifiers to define their visibility scope:

* `public`: Unrestricted access.
* `internal`: Access limited to the current assembly (default for top-level classes).
* `private`: Access limited to the containing class (default for class members).
* `protected`: Access limited to the containing class and derived classes.
* `protected internal`: Access limited to the current assembly OR derived classes.
* `private protected`: Access limited to the containing class OR derived classes within the same assembly.

**Class Modifiers**
The behavior and extensibility of a class can be altered using specific modifiers:

* `abstract`: Indicates the class is incomplete and cannot be instantiated. It must be inherited, and it may contain abstract methods that *concrete* (non-abstract) derived classes are forced to implement.
* `sealed`: Prevents the class from being inherited. This allows the runtime to apply certain optimizations, particularly in virtual method resolution.
* `static`: Indicates the class cannot be instantiated and can only contain static members. In the modern .NET ecosystem, static data is scoped and loaded into memory once per `AssemblyLoadContext`.
* `partial`: A contextual keyword and type modifier that allows the definition of a class to be split across multiple physical `.cs` files. The compiler merges them into a single class during compilation.

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