로딩
요청 처리 중입니다...

C# ref,out 키워드

 C# ref,out 키워드

ref, out 키워드 ref와 out 키워드는 인자로 넘긴 변수를 메서드 내부에서 참조 형태로 사용 한다는 점에서 동일하다. 속성(Property)은 변수가 아니므로 전달할 수 없다. using System; namespace Test { class Program { static void Main(string[] args) { int i = 0; modifyValue(ref i); Console.WriteLine(i); int j; modifyValueTwo(out j); Console.WriteLine(j); } static void modifyValue(ref int a) { a = 5; } static void modifyValueTwo(out int a) { a = 20; } } } // 5 // 20 두 키워드의 차이점 ref는 인자로 전달하기 전에 반드시 변수를 초기화를 해야 하지만, out은 초기화를 하지 않아도 된다. out은 메서드가 반환되기 전에 반드시 값을 할당...

원문 링크 : C# ref,out 키워드