
메소드
- 메소드는 일련의 코드를 하나의 이름 아래 묶는 것
- 클래스 안에 존재한다.
- 메소드는 매개 변수와 반환 형식을 가진다
ref 키워드
static void Swap( ref int a, ref int b )
{
int temp = b;
b = a;
a = temp;
}
int x = 3;
int y = 4;
Swap(ref x, ref y);
Class SomeClass
{
int SomeValue = 10;
public ref int SomeMethod()
{
return ref SomeValue;
}
}
SomeClass obj = new SomeClass();
int result = obj.SomeMethod();
SomeClass obj = new SomeClass();
ref int result = ref obj.SomeMethod();
out 키워드
- 출력 전용 매개 변수
- ref 와 사용법은 동일하나 ref에게 없는 안전장치가 있음
- ref 키워드를 이용해서 매개 변수를 넘기는 경우에는 메소드가 해당 매개 변수에 결과를 저장하지 않아도 문제 없음.
- out 키워드를 이용해서 매개 변수를 넘길 때는 메소드가 해당 매개 변수에 결과를 저장하지 않으면 에러를 출력함
가변길이 매개 변수
- 그 개수가 유연하게 변할 수 있는 매개 변수
- params 키워드와 배열을 이용해서 선언함
https://blockdmask.tistory.com/317
출처 : https://jaeho0613.tistory.com/96?category=819752