Questions tagged «system.type»

30
有没有比“打开类型”更好的选择了?
看到C#不能switch在类型上(我收集的这种数据没有作为特殊情况添加,因为is关系意味着case可能应用多个不同的对象),是否有更好的方法来模拟其他类型的切换? void Foo(object o) { if (o is A) { ((A)o).Hop(); } else if (o is B) { ((B)o).Skip(); } else { throw new ArgumentException("Unexpected type: " + o.GetType()); } }

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.