- 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 _);
推薦閱讀
- Deploying Node.js
- Oracle 11g從入門到精通(第2版) (軟件開發視頻大講堂)
- Practical Game Design
- INSTANT Django 1.5 Application Development Starter
- Mastering Linux Network Administration
- 新一代SDN:VMware NSX 網絡原理與實踐
- Babylon.js Essentials
- Android移動開發案例教程:基于Android Studio開發環境
- Hands-On GUI Programming with C++ and Qt5
- JSP程序設計實例教程(第2版)
- C編程技巧:117個問題解決方案示例
- SQL Server 入門很輕松(微課超值版)
- Flink技術內幕:架構設計與實現原理
- Learning C++ by Creating Games with UE4
- Applied Deep Learning with Python