C#入门经典 Part 4
Contents
CH 12
可空类型: System.Nullable<T>1
2System.Nullble<int> nullableInt;
nullableInt = null; // 等价于nullableInt = new System.Nullable<int>();
测试可空类型变量是否为null1
2if(nullableInt == null) // ...
if(nullableInt.HasValue) // ...
Value属性: nullableInt.Value。
int?是System.Nullble<int>的缩写,更便于读取。
??运算符op1 ?? op2等价于op1 == null ? op2 : op1。
System.Collections.Generic名空间包含的类型
List<T>Dictionary<K, V>
泛型委托类型(p295 - p297)
Comparison<T>返回类型和参数:int method(T objA, T objB)Predicate<T>返回类型和参数:bool method(T targetObj)
StringBuilder
Append()AppendFormat()
default关键字obj = default(T);: 根据类型为obj赋默认值。
约束类型1
2
3
4class MyGenericClass<T> where T : constraint1, contraint2
{
// ...
}