C#泛型对类型参数的推断

时间:2023-03-09 09:36:15
C#泛型对类型参数的推断
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 = , b = ;
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();
} }
}

运行效果图:

C#泛型对类型参数的推断

相关文章