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

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 _);
主站蜘蛛池模板: 瑞丽市| 荔波县| 靖宇县| 桐城市| 沾化县| 南漳县| 铁岭市| 杭锦旗| 五指山市| 怀远县| 石柱| 来凤县| 九台市| 聂荣县| 天气| 崇州市| 固安县| 咸丰县| 白河县| 岳西县| 丘北县| 穆棱市| 兰州市| 任丘市| 宿迁市| 雷州市| 玛沁县| 新余市| 新邵县| 桦川县| 濮阳市| 喜德县| 稻城县| 武威市| 于田县| 三原县| 民勤县| 五指山市| 浮梁县| 克东县| 肃宁县|