xiacy

导航

3.4.1 证明不同 服装类型具有不同的静态字段

    class TypeWithField<T>
    {
        public static string field;
        public static void PrintField()
        {
            Console.WriteLine(field + "" + typeof(T).Name);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            TypeWithField<int>.field = "first";
            TypeWithField<string>.field = "second";
            TypeWithField<DateTime>.field = "third";

            TypeWithField<int>.PrintField();//first:Int32
            TypeWithField<string>.PrintField();//second:String
            TypeWithField<DateTime>.PrintField();//third:DateTime
        }
    }

 

posted on 2012-05-01 13:38  xiacy  阅读(210)  评论(0编辑  收藏  举报