C#-_ =>();中的'_'有什么含义
_=方法(); 中的'_'为方法返回的结果放在堆栈中,不做存储。方法同步运行
Console.WriteLine("Hello, World!");
_ = Main1();  // 可以结束掉
_ = Main2();  // 死掉
Console.WriteLine("EndWorld!");
Console.ReadLine();
bool Main1()
{
    Console.WriteLine("H1!");
    Thread.Sleep(3000);
    try
    {
        throw new Exception($"Test1");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
// Thread.Sleep(1000); 
//throw new Exception($"[RW] NodeIdList不能为空");
    return true;
}
bool Main2()
{
    Console.WriteLine("H2!");
    Thread.Sleep(2000);
    throw new Exception($"Test2");
    return true;
}本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/16836664.html

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号