1869得票15回答
类型检查:typeof,GetType或is?

我看到很多人使用以下代码: Type t = typeof(SomeType); if (t == typeof(int)) // Some code here 但我知道你也可以这样做: if (obj1.GetType() == typeof(int)) // Som...

153得票17回答
在PHP中,MySQL整数字段被返回为字符串

我在MySQL数据库中有一个表格字段:userid INT(11) 所以我正在使用这个查询将它调用到我的页面:"SELECT userid FROM DB WHERE name='john'" 然后我用以下方式处理结果:$row=$result->fetch_assoc(); $id=...

123得票8回答
C# 'is'运算符的性能表现

我有一个需要快速运行的程序。在其中一个内部循环中,我需要测试对象的类型,以查看它是否继承自某个接口。 一种方法是使用CLR内置的类型检查功能。最优雅的方法可能是使用 'is' 关键字:if (obj is ISpecialType) 另一种方法是给基类自己定义一个虚拟的GetType()函数...

97得票4回答
何时何地使用GetType()或typeof()?

为什么这个方法可行if (mycontrol.GetType() == typeof(TextBox)) {} 那么这个不行吗?Type tp = typeof(mycontrol); 但是这个可以工作Type tp = mycontrol.GetType(); 我自己使用is运算符来检查类...

67得票7回答
Android获取视图类型

我该怎么做? 某些东西:final View view=FLall.getChildAt(i); if (view.getType()==ImageView) { ... }

61得票6回答
使用Assembly.LoadFrom()加载的程序集如何卸载?

我需要在加载dll后检查运行GetTypes()所需的时间。 代码如下。Assembly assem = Assembly.LoadFrom(file); sw = Stopwatch.StartNew(); var types1 = assem.GetTypes(); sw.Stop(); ...

49得票4回答
可空类型不是可空类型?

我正在测试可空类型,但结果并不像我预期的那样:int? testInt = 0; Type nullableType = typeof(int?); Assert.AreEqual(nullableType, testInt.GetType()); // not the same type 这...

40得票12回答
.NET:如何获取空对象的类型?

我有一个带有返回参数(out parameter)的方法,尝试进行类型转换。基本上如下: public void GetParameterValue(out object destination) { object paramVal = "I want to return this....

39得票5回答
C# 反射:如何获取 Nullable<int> 的类型?

我想要做的是像这样的事情:switch( myObject.GetType().GetProperty( "id") ) { case ??: // when Nullable&lt;Int32&gt;, do this case ??: //...

35得票3回答
如何通过类名获取类类型?

namespace Myspace { public class MyClass { } } //This class is in another file. using Myspace; static void Main(string[] args) { R...