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

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 _);
主站蜘蛛池模板: 兴安县| 托克托县| 深水埗区| 宜城市| 汶川县| 兴隆县| 楚雄市| 芦溪县| 泽州县| 广宗县| 莎车县| 六安市| 育儿| 邹平县| 鄂托克前旗| 巨鹿县| 安阳县| 朝阳县| 五峰| 伊川县| 友谊县| 边坝县| 交口县| 武隆县| 天气| 定襄县| 筠连县| 麻阳| 栾城县| 桂平市| 合作市| 寿阳县| 乌兰浩特市| 万年县| 盐边县| 厦门市| 原阳县| 肇源县| 延长县| 旬阳县| 抚宁县|