Skip to content

Instantly share code, notes, and snippets.

@jbogard
Last active October 27, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbogard/b617508a7679c8576698b7d707531530 to your computer and use it in GitHub Desktop.
Save jbogard/b617508a7679c8576698b7d707531530 to your computer and use it in GitHub Desktop.

Normal property

public class Person
{
    public string LastName { get; set; }
    public string MiddleName { get; set; }
    public string FirstName { get; set; }
}
.method public hidebysig specialname instance void 
        set_FirstName(string 'value') cil managed
{
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
  // Code size       8 (0x8)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldarg.1
  IL_0002:  stfld      string ConsoleApp1.Program/Person::'<FirstName>k__BackingField'
  IL_0007:  ret
} // end of method Person::set_FirstName

Init-only Record

public record Person
{
    public string LastName { get; init; }
    public string MiddleName { get; init; }
    public string FirstName { get; init; }
}
.method public hidebysig specialname instance void modreq([System.Runtime]System.Runtime.CompilerServices.IsExternalInit) 
        set_FirstName(string 'value') cil managed
{
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
  // Code size       8 (0x8)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldarg.1
  IL_0002:  stfld      string ConsoleApp1.Program/Person::'<FirstName>k__BackingField'
  IL_0007:  ret
} // end of method Person::set_FirstName

Positional-style Record

public record Person(
    string FirstName, 
    string MiddleName,
    string LastName);
.method public hidebysig specialname instance void modreq([System.Runtime]System.Runtime.CompilerServices.IsExternalInit) 
        set_LastName(string 'value') cil managed
{
  .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
  // Code size       8 (0x8)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldarg.1
  IL_0002:  stfld      string ConsoleApp1.Program/Person::'<LastName>k__BackingField'
  IL_0007:  ret
} // end of method Person::set_LastName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment