【发布时间】:2014-04-09 10:39:01
【问题描述】:
我对 C# 中的静态类在方法中的使用有疑问。假设我们在另一个类中有一个带有两个参数 int 和 Enum 的方法。
public void DemoMethod(int pricePerTenant , TenantType tenantType){
//Method implementation
}
如果我们实现一个静态类而不是 Enum,C# 不允许将静态类作为方法参数传递
public static class TenantType
{
public static readonly int TenantAdmin = 1;
public static readonly int TenantUser = 2;
public static readonly int PublicUser = 3;
}
//With static class parameters
public void DemoMethod(int pricePerTenant , TenantType tenantType){
//Method implementation
}
为什么 C# CLR 拒绝将静态类作为参数?
谢谢
【问题讨论】: