생활
c# 코드 짜는 중 궁금한 게 있습니다.
using System;class MainClass{ public static void Main(string[] args) { Action<object> print = Console.WriteLine; double a = 10.0, b = 20.0; Swap(ref a, ref b); print(a == 20.0 && b == 10.0); } static void Swap(ref double a, ref double b) { double temp; temp = a; a = b; b = temp; }}
위 코드에서 Swap 함수 앞에 왜 static이 붙어야 하는지 궁금합니다. 그리고 만약 static을 사용하지 않으려면 어떻게 고쳐야 하는지도 궁금합니다.
3개의 답변이 있어요!