04、c#2.0新功能.pptVIP

  • 0
  • 0
  • 约9.85千字
  • 约 36页
  • 2018-01-05 发布于河南
  • 举报
04、c#2.0新功能

C#2.0新功能 泛型 (Generic) 匿名方法 (Anonymous Method) 迭代器 (Iterator) 分部类型 (Partial Type) 可空类型 (Nullable Type) 泛型 (Generic) 泛型可以让类、结构、接口、委托和方法按它们存储和操作数据的类型进行参数化。 如果没有泛型,通用数据结构可通过使用类型 object 实现任何数据类型的存储。(但是类型不安全) 泛型提供了一种新的创建类型的机制,使用泛型创建的类型将带有类型形参 (type parameter) 泛型 (Generic)示例 public class Stack { object[] items; int count; public void Push(object item) {...} public object Pop() {...} } public class StackT { T[] items; int count; public void Push(T item) {...} public T Pop() {...} } 非泛型的使用 Stack stack = new Stack(); stack.Push(new Customer()); Customer c = (Customer)stack.Pop(); stack.Pus

文档评论(0)

1亿VIP精品文档

相关文档