现在的位置: 首页 > 综合 > 正文

C#中泛型特性4-静态成员

2013年08月08日 ⁄ 综合 ⁄ 共 599字 ⁄ 字号 评论关闭
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace 泛型
  6. {
  7.     class 泛型的特性
  8.     {
  9.         public static void Main()
  10.         { 
  11.             //泛型类的特性4 静态成员
  12.             Person<string>.Name = "aladdin";
  13.             Person<int>.Name = "zhao";
  14.             Console.WriteLine( Person<string>.Name ); //aladdin
  15.             Console.WriteLine( Person<int>.Name); // zhao
  16.             //泛型类的静成成员,只对实例共享。以上操作其实可以看做是两个类
  17.             Console.ReadLine();
  18.         }
  19.     }
  20.     class Person<T>
  21.     {
  22.         public static string Name;
  23.     }
  24.     class Person
  25.     {
  26.         public static string Name;
  27.     }
  28. }

抱歉!评论已关闭.