Generic Method 泛用方法 Generic Method 泛用方法
  .NET       ez      2011-11-30

以往使用的都稱為"泛型",int,double,string......

using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int number1 = 100;
            double number2 = 99.99;
            string str = "Generic Method";

            Console.WriteLine(GenericMethod<int>(number1));
            Console.WriteLine(GenericMethod<double>(number2));
            Console.WriteLine(GenericMethod<string>(str));
        }
        static GM GenericMethod<GM>(GM v)
        {
            GM r = v;
            return r;
        }
    }
}


標籤:   .NET

我要留言