use*_*667 5 c# enumeration typechecking
有人给我一个类型t.
我想知道这种类型是否是枚举.
public bool IsEnumeration(Type t)
{
// Mystery Code.
throw new NotImplementedException();
}
public void IsEnumerationChecker()
{
Assert.IsTrue(IsEnumeration(typeof(Color)));
Assert.IsFalse(IsEnumeration(typeof(float)));
}
Run Code Online (Sandbox Code Playgroud)
nan*_*nan 10
您还可以使用以下属性IsEnum 进行检查Type:
Type t = typeof(DayOfWeek);
bool isEnum = t.IsEnum;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
523 次 |
| 最近记录: |