Skip to content

Instantly share code, notes, and snippets.

@takecx
Created September 13, 2018 15:45
Show Gist options
  • Save takecx/9335a13fb58fe319bd0a251216f663e3 to your computer and use it in GitHub Desktop.
Save takecx/9335a13fb58fe319bd0a251216f663e3 to your computer and use it in GitHub Desktop.
out variable declaration sample(C# 7 new feature)
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