日期:2008-09-22  浏览次数:20445 次

写了点代码,初次体验到C#范型的魅力
class Program
{
static void WriteSometing<T>(T x,T y)
{
if (typeof(T) == typeof(int))
Console.WriteLine(x);
if (typeof(T) == typeof(string))
Console.WriteLine(y);
}

static void Main(string[] args)
{
WriteSometing<int>(0, 9);
WriteSometing<string>("0", "9");

WriteSometing(0, 9);
WriteSometing("0", "9");

Console.ReadLine();
}
}