ref와 out의 차이점1 [C#][Study][기초다지기] ref, out의 차이점 1. out - 매개변수를 참조로 전달 - 인수가 초기화 되지 않았어도 전달 가능 - 내부에서 변수에 값을 할당 해주어야 함 2. ref - 매개변수를 참조로 전달 - 인수가 초기화 되지 않은 경우 전달 불가(오류 발생) ex) using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace command { class Program { public static void Out(out int x) { x = 1; // 내부에서 해당 변수에 값을 할당 해주어야 함! x++; // 단독으로는 쓰일 수 없음 } public static void Reference(ref int x) { x++; } sta.. 2023. 9. 16. 이전 1 다음