- 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 _);
推薦閱讀
- PyTorch自動駕駛視覺感知算法實戰
- 軟件測試工程師面試秘籍
- Scratch 3游戲與人工智能編程完全自學教程
- concrete5 Cookbook
- Oracle Exadata專家手冊
- Mastering JavaScript Design Patterns(Second Edition)
- Swift 4 Protocol-Oriented Programming(Third Edition)
- Android開發三劍客:UML、模式與測試
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Raspberry Pi Blueprints
- Beginning PHP
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Raspberry Pi開發實戰
- C++標準庫(第2版)
- Mastering VMware vSphere Storage