C# 7.0에서 out 키워드를 좀더 사용하기 쉽게 변경되었다.

기존엔 변수선언을 하고 인자를 전달해야 했지만 C# 7.0 부터는 선언과 동시에 값을 전달 할 수 있도록 변경되었다.


아래 예제를 보자.

기존에 out 키워드를 사용하는 방식이다.

class TtestClass
{
	public void outTest(out int a)
	{
		a = 10;
	}
}
class Program
{
	static void Main(string[] args)
	{
		TtestClass t = new TtestClass();
		int b; //선언을 먼저 해주어야 한다.
		t.outTest(out b);
		Console.WriteLine("b : " + b);
	}
}	


아래는 C# 7.0에서 변경된 방식이다.

class TtestClass
{
	public void outTest(out int a)
	{
		a = 10;
	}
}
class Program
{
	static void Main(string[] args)
	{
		TtestClass t = new TtestClass();
		t.outTest(out int b); //선언과 동시에 인자 전달
		Console.WriteLine("b : " + b);
	}
}


Posted by 꿈만은공돌
,