using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 泛型对类型参数的推断 { class Program { public static void genericMtthod<T>( T t1, T t2) { T temp = t1; t1 = t2; t2 = temp; } static void Main(string[] args) { int a = 1, b = 2; genericMtthod( a, b); Console.WriteLine("a:" + a); Console.WriteLine("b:" + b); string c="c",d="d"; genericMtthod( c, d); Console.WriteLine("c:" + c); Console.WriteLine("d:" + d); Console.ReadKey(); } } }
运行效果图:
时间: 2025-01-04 04:56:03