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);
}
}
'닷넷,C#,.NET' 카테고리의 다른 글
| C#/.NET 연산자 오버로딩(operator) (0) | 2018.05.08 |
|---|---|
| C#/.NET get,set 키워드를 이용한 프로퍼티 (1) | 2018.05.08 |
| C#/.NET readonly vs const 예제로 보는 차이점 (0) | 2018.05.06 |
| C#/.NET 가비지 컬렉션의 메모리 할당 및 해제 기본 원리 (Garbage collection) (0) | 2018.05.02 |
| C#/.NET Dictionary 콜렉션 인자 추가(Add) 및 삭제(Remove) (0) | 2018.04.24 |


