柚子快报邀请码778899分享:C#泛型对类型参数的推断

http://www.51969.com/

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 泛型对类型参数的推断

{

class Program

{

public static void genericMtthod( 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();

}

}

}

运行效果图:

 

柚子快报邀请码778899分享:C#泛型对类型参数的推断

http://www.51969.com/

查看原文