TryParse with out var param

后端 未结 3 384
臣服心动
臣服心动 2020-12-09 00:19

A new feature in C# 6.0 allows to declare variable inside TryParse method. I have some code:

string s = \"Hello\";

if (int.TryParse(s, out var result))
{

}         


        
3条回答
  •  Happy的楠姐
    2020-12-09 01:03

    Just found out by accident, in vs2017, you can do this for brevity:

    if (!Int64.TryParse(id, out _)) {
       // error or whatever...
    }
    

提交回复
热议问题