Skip to content

Instantly share code, notes, and snippets.

@rodion-m
Last active June 4, 2021 20:17
Show Gist options
  • Save rodion-m/9e33b466f293bb401eba7c7a648417ad to your computer and use it in GitHub Desktop.
Save rodion-m/9e33b466f293bb401eba7c7a648417ad to your computer and use it in GitHub Desktop.
Null vs Void CSharp - IL

NULL

object? GoNull() {
 return null;   
}

As IL:

    .method assembly hidebysig static 
        object '<<Main>$>g__GoNull|0_0' () cil managed 
    {
        // Method begins at RVA 0x2094
        // Code size 7 (0x7)
        .maxstack 1
        .locals init (
            [0] object
        )

        IL_0000: nop
        IL_0001: ldnull
        IL_0002: stloc.0
        IL_0003: br.s IL_0005

        IL_0005: ldloc.0
        IL_0006: ret
    } // end of method '<Program>$'::'<<Main>$>g__GoNull|0_0'

VOID

void GoVoid() {
}

As IL:

    .method assembly hidebysig static 
        void '<<Main>$>g__GoVoid|0_1' () cil managed 
    {
        // Method begins at RVA 0x20a7
        // Code size 2 (0x2)
        .maxstack 8

        IL_0000: nop
        IL_0001: ret
    } // end of method '<Program>$'::'<<Main>$>g__GoVoid|0_1'

Created with sharplab.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment