• λ我爱Aspx >> C#.Net >> c#泛型学习(二)_C#教程
  • c#泛型学习(二)_C#教程

  • :aspxer  Դ:internet  :2007-4-28 20:58:03  ؼ:c#
  • 53 {

    54 if (t is int) { }

    55 if (t is LinkedList<int, string>) { }

    56 string str = t as string;

    57 if (str != null) { }

    58 LinkedList<int, string> list = t as LinkedList<int, string>;

    59 if (list != null) { }

    60 }

    61 }

    62 #endregion

    63

    64}

    65

    2.继承和泛型

    1using System;

    2using System.Collections.Generic;

    3using System.Text;

    4

    5namespace VS2005Demo2

    6{

    7 继承和泛型#region 继承和泛型

    8 public class BaseClass<T>

    9 { }

    10 public class SubClass : BaseClass<int>

    11 { }

    12

    13

    14 public class SubClass1<R> : BaseClass<R>

    15 { }

    16 #endregion

    17

    18 继承约束#region 继承约束

    19 public class BaseClass1<T> where T : ISomeInterface

    20 { }

    21 public class SubClass2<T> : BaseClass1<T> where T : ISomeInterface

    22 { }

    23

    24 //构造函数约束

    25 public class BaseClass3<T> where T : new()

    26 {

    27 public T SomeMethod()

    28 {

    29 return new T();

    30 }

    31 }

    32 public class SubClass3<T> : BaseClass3<T> where T : new()

    33 { }

    34

    35 #endregion

    36

    37 虚拟方法#region 虚拟方法

    38 public class BaseClass4<T>

    39 {

    40 public virtual T SomeMethod()

    41 {

    Ҷƪл˵?
  • һƪc#2.0泛型学习(一) _C#教程
    һƪC# 3.0新特性初步研究 Part1:使用隐含类型的本地变量_C#教程