static void Main(string[] args) { int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7 }; ReverseAndPrint <string>(new string[] { "1", "2", "3" }); ReverseAndPrint(arr);//这里编译器可 推断类型 //扩展方法 var intH = new Hodler <int>(1, 2, 3); var stringH = new Hodler <string>("1", "2", "3"); intH.Print(); stringH.Print(); Console.ReadKey(); }
public static void Print <T>(this Hodler <T> hodler) //this关键字和类型 { T[] vals = hodler.GetValue(); Console.WriteLine("{0},{1},{2}", vals[0], vals[1], vals[2]); }