internal class Program
{
public static void SwapCallByValue(int a, int b)
{
int temp = b;
b = a;
a = temp;
}
public static void SwapCallByRef(ref int a, ref int b)
{
int temp = b;
b = a;
a = temp;
}
public static void Main(string[] args)
{
int x = 3;
int y = 4;
Console.WriteLine("x:{0}, y{1}",x, y);
// SwapCallByValue(x, y);
SwapCallByRef(ref x, ref y);
Console.WriteLine("x:{0}, y{1}",x, y);
}
}
x: 3, y: 4
x: 4, y: 3
'c#' 카테고리의 다른 글
| 인덱서 (0) | 2021.04.16 |
|---|---|
| c# Auto properties (0) | 2021.04.15 |
| 가변길이 매개변수 params (0) | 2021.04.14 |
| c# out 키워드 두 개 이상의 결과를 내보낼 때 사용 (0) | 2021.04.13 |
| c# ref return (0) | 2021.04.13 |