Skip to content

Instantly share code, notes, and snippets.

@LucasOe
Last active September 9, 2025 08:57
Show Gist options
  • Select an option

  • Save LucasOe/e1793b61e987ad737868d7d0ca6ca842 to your computer and use it in GitHub Desktop.

Select an option

Save LucasOe/e1793b61e987ad737868d7d0ca6ca842 to your computer and use it in GitHub Desktop.

C# Types

---
config:
  flowchart:
    curve: linear
  theme: dark
---
flowchart TD
    subgraph RecordStruct["record struct"]
        direction TB
        RecordStructReadonly{{"mutable / immutable"}}
        RecordStructReadonlyPositional{{"positional parameters?"}}
        ReadonlyPositionalRecordStructT["public readonly record struct Point(double X, double Y);"]
        PositionalRecordStructT["public record struct Point <br>{<br>    public double X { get; init; }<br>    public double Y { get; init; }<br>}"]
        RecordStructPositional{{"positional parameters?"}}
        ReadonlyRecordStructT["public record struct Point(double X, double Y);"]
        RecordStructT["public record struct Point <br>{<br>    public double X { get; set; }<br>    public double Y { get; set; }<br>}"]
    end
    subgraph RecordClass["record class"]
        direction TB
        RecordPositional{{"positional parameters?"}}
        PositionalReadonlyRecordT["public record Point(double X, double Y);"]
        ReadonlyRecordT["public record Person<br>{<br>    public required string FirstName { get; init; }<br>    public required string LastName { get; init; }<br>};"]
    end
    subgraph Record["record"]
        direction TB
        RecordStruct
        RecordClass
    end
    subgraph RefStruct["ref struct"]
        direction TB
        RefStructReadonly{{"immutable / mutable"}}
        ReadonlyRefStructT["public readonly ref struct ConversionRequest<br>{<br>    public ConversionRequest(double rate, ReadOnlySpan values)<br>    {<br>        Rate = rate;<br>        Values = values;<br>    }<br><br>    public double Rate { get; }<br>    public ReadOnlySpan Values { get; }<br>}"]
        RefStructT["public ref struct CustomRef<br>{<br>    public bool IsValid;<br>    public Span Inputs;<br>    public Span Outputs;<br>}"]
    end
    subgraph Struct["struct"]
        direction TB
        StructReadonly{{"immutable / mutable"}}
        ReadonlyStructT["public readonly struct Point <br>{<br>    public double X { get; init; }<br>    public double Y { get; init; }<br><br>     public Coords(double x, double y)<br>     {<br>          X = x;<br>          Y = y;<br>     }<br>}"]
        StructT["public struct Point <br>{<br>    public double X { get; set; }<br>    public double Y { get; set; }<br><br>     public Coords(double x, double y)<br>     {<br>          X = x;<br>          Y = y;<br>     }<br>}"]
    end
    subgraph Structs["struct"]
        direction TB
        StructStackHeap{{"stack / heap"}}
        RefStruct
        Struct
    end
    subgraph Class["class"]
        direction TB
        ClassT["class TestClass<br>{<br>    // Methods, properties, fields, events, delegates<br>    // and nested classes go here.<br>}"]
    end
    subgraph Enum["enum"]
        direction TB
        EnumExhaustive{{"exhaustive?"}}
        EnumT["enum Season<br>{<br>    Spring,<br>    Summer,<br>    Autumn,<br>    Winter<br>}"]
        ClosedEnumT["closed enum Season<br>{<br>    Spring,<br>    Summer,<br>    Autumn,<br>    Winter<br>}"]
    end
    subgraph Union["union (proposal)"]
        direction TB
        UnionT["public union Pet(Cat, Dog);"]
        UnionCaseT["public union Pet {<br>    case Cat(string Name, string Personality);<br>    case Dog(string Name, string Breed);<br>    case Bird(string Name, string Species);<br>}"]
    end
    subgraph Inheritance["inheritance"]
        direction TB
        InheritanceT["abstract record IpAddr<br>{<br>    public sealed record V4(byte A, byte B, byte C, byte D) : IpAddr;<br>    public sealed record V6(string Address) : IpAddr;<br>}"]
    end

    A{{"C# Types"}} --> Product("**structure type / product type**<br>(encapsulates data and related functionality)") & Sum("**enumeration type / sum type**<br>(represents a choice or a combination of choices)")
    Product --> ClassOrRecord{{"Built-in functionality for encapsulating data?<br>(value equality / concise syntax)"}}
    ClassOrRecord -- yes --> Record
    ClassOrRecord -- no --> Structs & Class
    Sum --> Enum & Union & Inheritance

    RecordStructReadonly -- immutable --> RecordStructReadonlyPositional
    RecordStructReadonlyPositional -- yes --> ReadonlyPositionalRecordStructT
    RecordStructReadonlyPositional -- no --> PositionalRecordStructT
    RecordStructReadonly -- mutable --> RecordStructPositional
    RecordStructPositional -- yes --> ReadonlyRecordStructT
    RecordStructPositional -- no --> RecordStructT
    RecordPositional -- yes --> PositionalReadonlyRecordT
    RecordPositional -- no --> ReadonlyRecordT
    StructStackHeap -- always stack --> RefStruct
    StructStackHeap -- stack or heap --> Struct
    RefStructReadonly -- immutable --> ReadonlyRefStructT
    RefStructReadonly -- mutable --> RefStructT
    StructReadonly -- immutable --> ReadonlyStructT
    StructReadonly -- mutable --> StructT
    EnumExhaustive -- no --> EnumT
    EnumExhaustive -- yes (proposal) --> ClosedEnumT


    ReadonlyPositionalRecordStructT:::code
    PositionalRecordStructT:::code
    ReadonlyRecordStructT:::code
    RecordStructT:::code
    PositionalReadonlyRecordT:::code
    ReadonlyRecordT:::code
    ReadonlyRefStructT:::code
    RefStructT:::code
    ReadonlyStructT:::code
    StructT:::code
    ClassT:::code
    EnumT:::code
    ClosedEnumT:::code
    UnionT:::code
    UnionCaseT:::code
    InheritanceT:::code

    classDef default white-space:pre
    classDef code text-align:left

    style Record fill:transparent,stroke:#000000
    style Structs fill:transparent,stroke:#000000
    style RecordStruct fill:#BBDEFB,color:#000000,stroke:none
    style RecordClass fill:#C8E6C9,color:#000000,stroke:none
    style RefStruct fill:#BBDEFB,color:#000000,stroke:none
    style Struct fill:#BBDEFB,color:#000000,stroke:none
    style Class fill:#C8E6C9,color:#000000,stroke:none
    style Enum fill:#BBDEFB,color:#000000,stroke:none
    style Union fill:#BBDEFB,color:#000000,stroke:none
    style Inheritance fill:#C8E6C9,color:#000000,stroke:none

    linkStyle 9 stroke:#000000,fill:none
    linkStyle 10 stroke:#000000,fill:none
    linkStyle 11 stroke:#000000,fill:none
    linkStyle 12 stroke:#000000,fill:none
    linkStyle 13 stroke:#000000,fill:none
    linkStyle 14 stroke:#000000,fill:none
    linkStyle 15 stroke:#000000,fill:none
    linkStyle 16 stroke:#000000,fill:none
    linkStyle 19 stroke:#000000,fill:none
    linkStyle 20 stroke:#000000,fill:none
    linkStyle 21 stroke:#000000,fill:none
    linkStyle 22 stroke:#000000,fill:none
    linkStyle 23 stroke:#000000,fill:none
    linkStyle 24 stroke:#000000,fill:none
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment