Skip to content

properties

Andrew Matthews edited this page Aug 30, 2025 · 1 revision

5th Code Generation for Properties

Here's a sample of the IL generated for a property, by dotnet:

  .class public auto ansi beforefieldinit
    ConsoleApp1.Person
      extends [System.Runtime]System.Object
  {
    .method public hidebysig specialname rtspecialname instance void
      .ctor() cil managed
    {
      .maxstack 8
  
      IL_0000: ldarg.0      // this
      IL_0001: call         instance void [System.Runtime]System.Object::.ctor()
      IL_0006: nop
      IL_0007: ret
  
    } // end of method Person::.ctor
    
   .field private string '<Name>k__BackingField'
     .method public hidebysig specialname instance string
      get_Name() cil managed
    {
      .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
        = (01 00 00 00 )
      .maxstack 8
  
      // [5 26 - 5 30]
      IL_0000: ldarg.0      // this
      IL_0001: ldfld        string ConsoleApp1.Person::'<Name>k__BackingField'
      IL_0006: ret
  
    } // end of method Person::get_Name
  
    .method public hidebysig specialname instance void
      set_Name(
        string 'value'
      ) cil managed
    {
      .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
        = (01 00 00 00 )
      .maxstack 8
  
      // [5 31 - 5 35]
      IL_0000: ldarg.0      // this
      IL_0001: ldarg.1      // 'value'
      IL_0002: stfld        string ConsoleApp1.Person::'<Name>k__BackingField'
      IL_0007: ret
  
    } // end of method Person::set_Name
    
    .property instance string Name()
    {
      .get instance string ConsoleApp1.Person::get_Name()
      .set instance void ConsoleApp1.Person::set_Name(string)
    } // end of property Person::Name
  }
Clone this wiki locally