int? len = null;
int max = len ?? 10;
用于在一个可空类型的元素上做三元运算时的快捷方式,如果不为null则取它的值,如果为null,则取后面的值(这里是10)。
public static class Class1
{
public static int Test(this int aaa)
{
return 0;
}
}
this操作符,标识该方法是作为后跟类型(这里是int)的扩展方法,即在int类型上增加Test()方法。
附protected internal访问修饰符,这个比较少用:
protected限定的是只有在继承的子类中才可以访问,可以跨程序集
internal限定的是只有在同一个程序集中才可以访问,可以跨类
protected internal 的访问范围是:本程序集、继承的子类。
很长时间不用,就会忘掉的。。。。
2010-05-21更新:
public interface IEntityProvider<Entity, EntityKey>
where Entity : IEntityId<EntityKey>, new()
where EntityKey : IEntityKey, new()
where T : new() 表示T这个类型需要拥有一个无参的构造方法。