1、傳值

 1static void Main(string[] args)
 2{
 3  int n=10;
 4  add(n);
 5  Console.WriteLine(n);//n=10
 6
 7}

 8
 9private static void add(int num)
10{
11  num++;
12}
2、傳引用ref、out
 
 1        static void Main(string[] args)
 2        {
 3            int a = 7;
 4            add(ref a);
 5            Console.WriteLine(a);//a=8
 6        }

 7
 8        public static void add(ref int num) {
 9            num++;
10        }
ref與out都為傳引用,主要的區別在于:ref前綴的參數在傳入前必須初始化,而out前綴的參數則不然,可以在調用函數里初始化參數。