方法中的参数 值参数 不含任何参数引用参数 以ref修饰符声明输出参数 以out修饰符声明数组参数 以params修饰符声明 注:如果形参表中包含了数组参数,那么他必须在参数表的最后。另外,参数只能是一维数组,不能再被ref和out修饰 using System; using System.Collections.Generic; using System.Text; //方法 namespace Methods { class Program { public static int max(int x, int y) //1、值参数不含任何修饰符 { if (x > y) return x; else return y; } public static void swap(ref int x, ref int y)//2、引用型参数,传递的是地址 { int temp; temp = x; x = y; y = temp; } static void SplitPath(string path, out string dir, out string name) //3、输出型参数 { int i = path.Length; while (i > 0) { char ch = path[i - 1]; if (ch == '//' || ch == '/' || ch == ':') break; //注意此处 i--; } dir = path.Substring(0, i); name = path.Substring(i); } static void F(params int[] args) //4、数组参数 { Console.WriteLine("Array have {0} elements."); foreach (int i in args) Console.Write("{0}",i); Console.WriteLine(); } static void Main(string[] args) { int i = 1, j = 2; swap(ref i, ref j); Console.WriteLine("i={0},j={1}", i, j); string dir, name; SplitPath("C://DRIVER//NV4_DISP.DL_",out dir,out name); Console.WriteLine("dir={0},name={1}", dir, name); Console.WriteLine("The max of 6 and 8 is:{0}",max(6,8)); int[] a ={ 1, 2, 3 }; //数组几种不同的传参形式 F(a); F(10, 20, 30, 40); F(); Console.ReadLine(); } } }