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

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 _);
主站蜘蛛池模板: 郴州市| 尚义县| 巴彦县| 准格尔旗| 江达县| 惠东县| 寿阳县| 贞丰县| 东港市| 河曲县| 合川市| 唐山市| 东方市| 涿州市| 射洪县| 盖州市| 偃师市| 阿克苏市| 水城县| 澎湖县| 寿阳县| 化德县| 周宁县| 湘西| 莎车县| 宁武县| 曲周县| 永城市| 开江县| 璧山县| 义马市| 乐陵市| 睢宁县| 交城县| 嘉善县| 定襄县| 镇宁| 贵德县| 加查县| 大足县| 溧水县|