官术网_书友最值得收藏!

Out variables

If you want to pass parameters to a method for modification, then you always need to declare them first. This is no longer necessary, and you can simply declare the variables at the point you pass them in. You can also declare a variable to be discarded, using an underscore. This is particularly useful if you don't want to use the returned value, for example, in some of the try parse methods of the native framework data types.

Here, we parse a date without declaring the dt variable first:

DateTime.TryParse("2017-08-09", out var dt);

In this example, we test for an integer, but we don't care what it is:

var isInt = int.TryParse("w00t", out _);
主站蜘蛛池模板: 呼和浩特市| 阜康市| 兴安县| 淮阳县| 右玉县| 集贤县| 南丹县| 潞城市| 韶山市| 防城港市| 龙泉市| 黄山市| 峨眉山市| 沭阳县| 肥乡县| 科尔| 青铜峡市| 田东县| 库车县| 青海省| 镇江市| 秦安县| 黑河市| 垣曲县| 华安县| 绥棱县| 木兰县| 武威市| 库车县| 合作市| 武山县| 保靖县| 建德市| 肇源县| 孝感市| 武功县| 屏东市| 镇平县| 广平县| 乐亭县| 治多县|