namespace csharp6
{
internal class Person
{
public string Name { get; set; }
}
internal class Program
{
private static void Main()
{
Person person = null;
string name = null;
if (person != null)
{
name = person.Name;
}
}
}
}
namespace csharp6
{
internal class Person
{
public string Name { get; set; }
}
internal class Program
{
private static void Main()
{
Person person = null;
string name = person?.Name;
}
}
}
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 23 (0x17)
.maxstack 2
.locals init ([0] class csharp6.Person person,
[1] string name,
[2] bool V_2)
IL_0000: nop
IL_0001: ldnull
IL_0002: stloc.0
IL_0003: ldnull
IL_0004: stloc.1
IL_0005: ldloc.0
IL_0006: ldnull
IL_0007: cgt.un
IL_0009: stloc.2
IL_000a: ldloc.2
IL_000b: brfalse.s IL_0016
IL_000d: nop
IL_000e: ldloc.0
IL_000f: callvirt instance string csharp6.Person::get_Name()
IL_0014: stloc.1
IL_0015: nop
IL_0016: ret
} // end of method Program::Main
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 17 (0x11)
.maxstack 1
.locals init ([0] class csharp6.Person person,
[1] string name)
IL_0000: nop
IL_0001: ldnull
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: brtrue.s IL_0009
IL_0006: ldnull
IL_0007: br.s IL_000f
IL_0009: ldloc.0
IL_000a: call instance string csharp6.Person::get_Name()
IL_000f: stloc.1
IL_0010: ret
} // end of method Program::Main
.method private hidebysig static void Main() cil managed
{
.entrypoint
// Code size 17 (0x11)
.maxstack 1
.locals init ([0] class csharp6.Person person,
[1] string name)
IL_0000: nop
IL_0001: ldnull
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: brtrue.s IL_0009
IL_0006: ldnull
IL_0007: br.s IL_000f
IL_0009: ldloc.0
IL_000a: callvirt instance string csharp6.Person::get_Name()
IL_000f: stloc.1
IL_0010: ret
} // end of method Program::Main
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 2
.locals init ([0] class csharp6.Person person, //初始化局部变量person,把person放在索引为0的位置
[1] string name, //初始化局部变量name,把name放在索引为1的位置
[2] bool V_2) //初始化局部变量V_2,把V_2放在索引为2的位置
IL_0000: nop //空
IL_0001: ldnull //加载null
IL_0002: stloc.0 //把null放入索引为0的变量,也就是person对象。
IL_0003: ldnull //加载null
IL_0004: stloc.1 //把null放入索引为1的变量,也就是name对象。
IL_0005: ldloc.0 //加载索引为0的位置的变量,也就是person对象
IL_0006: ldnull //加载null
IL_0007: cgt.un //比较前两步加载的值。如果第一个值大于第二个值,则将整数值1推送到计算堆栈上;反之,将0推送到计算堆栈上。
IL_0009: stloc.2 //把比较结果放入索引为2的变量中,也就是V_2对象
IL_000a: ldloc.2 //加载索引为2的对象,也就是V_2对象
IL_000b: brfalse.s IL_0016 //如果上一步加载的对象为false、空引用或零,则跳转到IL_0016位置,也就是结束当前方法。
IL_000d: nop //空
IL_000e: ldloc.0 //加载索引为0的位置的变量,也就是person对象
IL_000f: callvirt instance string csharp6.Person::get_Name() //调用person对象的get_Name方法。
IL_0014: stloc.1 //把上一步的结果存入索引为1的变量中,也就是name对象。
IL_0015: nop //空
IL_0016: ret //返回
}
.method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 1
.locals init ([0] class csharp6.Person person, //初始化局部变量person,把person放在索引为0的位置
[1] string name) //初始化局部变量name,把name放在索引为1的位置
IL_0000: nop //空
IL_0001: ldnull //加载null
IL_0002: stloc.0 //把null放入索引为0的变量,也就是person对象
IL_0003: ldloc.0 //加载索引为0的位置的变量,也就是person对象
IL_0004: brtrue.s IL_0009 //如果上一步加载的对象为true、非空引用或非零,则跳转到IL_0009位置
IL_0006: ldnull //加载null
IL_0007: br.s IL_000f //无条件的跳转到IL_000f处
IL_0009: ldloc.0 //加载索引为0的位置的变量,也就是person对象
IL_000a: call instance string csharp6.Person::get_Name() ////调用person对象的get_Name方法。
IL_000f: stloc.1 //把上一步的结果存入索引为1的变量中,也就是name对象。
IL_0010: ret //返回
}
Person[] persons = null; //?. int? length = persons?.Length; //?[ Person first = persons?[0];
PropertyChangedEventHandler propertyChanged = PropertyChanged;
if (propertyChanged != null)
{
propertyChanged(this, new PropertyChangedEventArgs(nameof(Name)));
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有