Den*_*gan 3 c#
检查C#中变量的类型有多贵?
例如使用try/ catchvs.使用as与使用typeof.
try
catch
as
typeof
绝对测量不是必需的.:)
Ric*_*lay 5
try/ catch肯定是慢的,因为抛出的异常会导致收集堆栈信息.
as/ is用于与编译时已知的类型进行比较并满足继承(即"string" is Object返回true)
is
"string" is Object
true
typeof/ GetType()可以用于运行时已知的类型但不满足继承(即"string".GetType() == typeof(Object)返回false)
GetType()
"string".GetType() == typeof(Object)
false
无论如何,我想你可能想要as(或者is如果你不需要演员值)
归档时间:
16 年,1 月 前
查看次数:
209 次
最近记录: