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;
}
posted @ 2022-10-28 16:55  ꧁执笔小白꧂  阅读(450)  评论(0)    收藏  举报