我看到很多人使用以下代码: Type t = typeof(SomeType); if (t == typeof(int)) // Some code here 但我知道你也可以这样做: if (obj1.GetType() == typeof(int)) // Som...
我有一个需要快速运行的程序。在其中一个内部循环中,我需要测试对象的类型,以查看它是否继承自某个接口。 一种方法是使用CLR内置的类型检查功能。最优雅的方法可能是使用 'is' 关键字:if (obj is ISpecialType) 另一种方法是给基类自己定义一个虚拟的GetType()函数...
我该怎么做? 某些东西:final View view=FLall.getChildAt(i); if (view.getType()==ImageView) { ... }
我需要在加载dll后检查运行GetTypes()所需的时间。 代码如下。Assembly assem = Assembly.LoadFrom(file); sw = Stopwatch.StartNew(); var types1 = assem.GetTypes(); sw.Stop(); ...
我正在测试可空类型,但结果并不像我预期的那样:int? testInt = 0; Type nullableType = typeof(int?); Assert.AreEqual(nullableType, testInt.GetType()); // not the same type 这...
我有一个带有返回参数(out parameter)的方法,尝试进行类型转换。基本上如下: public void GetParameterValue(out object destination) { object paramVal = "I want to return this....
我想要做的是像这样的事情:switch( myObject.GetType().GetProperty( "id") ) { case ??: // when Nullable<Int32>, do this case ??: //...
namespace Myspace { public class MyClass { } } //This class is in another file. using Myspace; static void Main(string[] args) { R...