Created
September 13, 2018 15:45
-
-
Save takecx/9335a13fb58fe319bd0a251216f663e3 to your computer and use it in GitHub Desktop.
out variable declaration sample(C# 7 new feature)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace out_variable_declaration_sample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string integerStr = "5"; | |
// 一時変数を使う版 | |
int temp; | |
if(int.TryParse(integerStr,out temp)) | |
{ | |
Console.WriteLine("temporaly : " + temp); | |
} | |
//出力変数宣言(out variable declaration)を使う版 | |
if(int.TryParse(integerStr,out var number)){ | |
Console.WriteLine("out variable declaration : " + number); | |
} | |
/* | |
出力 | |
temporaly : 5 | |
out variable declaration : 5 | |
*/ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment