C# 泛型 引用类型约束 值类型约束
2015-05-07 00:25
435 查看
引用类型约束:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace referenceConstraint { class Myclass { } class GenClass<T> where T : class { T field; public GenClass() { field = null; } } class Program { static void Main(string[] args) { GenClass<Myclass> g = new GenClass<Myclass>(); Console.ReadLine(); } } }2、值类型约束:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace referenceConstraint { class Myclass { } class GenClass<T> where T : struct { T field; public GenClass(T fld) { field = fld; } } class Program { static void Main(string[] args) { GenClass<int> g = new GenClass<int>(0); Console.ReadLine(); } } }
相关文章推荐
- C#的泛型的类型参数可以有带参数的构造函数的约束方式吗?
- 关于C#中泛型类型参数约束(where T : class)
- where(泛型类型约束)(C# 参考)
- c# 泛型 类型参数的约束(C# 编程指南)
- c# where(泛型类型约束)
- C#中的泛型(类型参数的约束)
- C# 学习教程 之 泛型类型参数的限制约束和代码实例
- C# 泛型类型参数的约束
- C# 泛型类型参数的约束
- [转] C# 泛型类型参数的约束
- C#的泛型的类型参数可以有带参数的构造函数的约束方式吗
- 关于C#中泛型类型参数约束(where T : class)
- C# 泛型类型参数的约束
- c# in depth之泛型的类型约束详细
- C# 泛型类型参数的约束
- c#泛型类型的约束条件where
- c# 泛型类型参数T的约束where
- 泛型约束(值类型和引用类型)
- c#中的WHERE语句 ——where(泛型类型约束)