- ASP.NET Core 2 High Performance(Second Edition)
- James Singleton
- 116字
- 2021-07-08 09:38:59
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 _);
推薦閱讀
- PHP 7底層設(shè)計(jì)與源碼實(shí)現(xiàn)
- Apache Spark Graph Processing
- 深入理解Java7:核心技術(shù)與最佳實(shí)踐
- Expert Android Programming
- 軟件測試技術(shù)指南
- PhoneGap:Beginner's Guide(Third Edition)
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- 從零開始學(xué)Linux編程
- Lighttpd源碼分析
- Visual Basic 6.0程序設(shè)計(jì)實(shí)驗(yàn)教程
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)(第二版)
- .NET 4.0面向?qū)ο缶幊搪劊簯?yīng)用篇
- 編程的原則:改善代碼質(zhì)量的101個方法
- Software Architecture with Python
- PHP典型模塊與項(xiàng)目實(shí)戰(zhàn)大全