内联函数

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int a = M();

            int M()
            {
                return 1;
            }
        }
    }
}
.class private auto ansi beforefieldinit ConsoleApp1.Program
    extends [mscorlib]System.Object
{
    // Methods
    .method private hidebysig static 
        void Main (
            string[] args
        ) cil managed 
    {
        // Method begins at RVA 0x2050
        // Header size: 12
        // Code size: 9 (0x9)
        .maxstack 1
        .entrypoint
        .locals init (
            [0] int32 a
        )

        IL_0000: nop
        IL_0001: call int32 ConsoleApp1.Program::'<Main>g__M|0_0'()
        IL_0006: stloc.0
        IL_0007: nop
        IL_0008: ret
    } // end of method Program::Main

    .method public hidebysig specialname rtspecialname 
        instance void .ctor () cil managed 
    {
        // Method begins at RVA 0x2065
        // Header size: 1
        // Code size: 8 (0x8)
        .maxstack 8

        IL_0000: ldarg.0
        IL_0001: call instance void [mscorlib]System.Object::.ctor()
        IL_0006: nop
        IL_0007: ret
    } // end of method Program::.ctor

    .method assembly hidebysig static 
        int32 '<Main>g__M|0_0' () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
            01 00 00 00
        )
        // Method begins at RVA 0x2070
        // Header size: 12
        // Code size: 7 (0x7)
        .maxstack 1
        .locals init (
            [0] int32
        )

        IL_0000: nop
        IL_0001: ldc.i4.1
        IL_0002: stloc.0
        IL_0003: br.s IL_0005

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

} // end of class ConsoleApp1.Program
IL中间语言

以下不是内联函数

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int a = M();
        }

        static int M()
        {
            return 1;
        }
    }
}
不是内联函数
.namespace ConsoleApp1
{
    .class private auto ansi beforefieldinit ConsoleApp1.Program
        extends [mscorlib]System.Object
    {
        // Methods
        .method private hidebysig static 
            void Main (
                string[] args
            ) cil managed 
        {
            // Method begins at RVA 0x2050
            // Header size: 12
            // Code size: 8 (0x8)
            .maxstack 1
            .entrypoint
            .locals init (
                [0] int32 a
            )

            IL_0000: nop
            IL_0001: call int32 ConsoleApp1.Program::M()
            IL_0006: stloc.0
            IL_0007: ret
        } // end of method Program::Main

        .method private hidebysig static 
            int32 M () cil managed 
        {
            // Method begins at RVA 0x2064
            // Header size: 12
            // Code size: 7 (0x7)
            .maxstack 1
            .locals init (
                [0] int32
            )

            IL_0000: nop
            IL_0001: ldc.i4.1
            IL_0002: stloc.0
            IL_0003: br.s IL_0005

            IL_0005: ldloc.0
            IL_0006: ret
        } // end of method Program::M

        .method public hidebysig specialname rtspecialname 
            instance void .ctor () cil managed 
        {
            // Method begins at RVA 0x2077
            // Header size: 1
            // Code size: 8 (0x8)
            .maxstack 8

            IL_0000: ldarg.0
            IL_0001: call instance void [mscorlib]System.Object::.ctor()
            IL_0006: nop
            IL_0007: ret
        } // end of method Program::.ctor

    } // end of class ConsoleApp1.Program

}
IL中间语言
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值