波光粼粼涟漪诊疗所,蕉下小黑伞,特种黑道
if(obj is t) { t value = (t) obj; }
t value = obj as t; if(value !=null) { }
测试例子:
class testclass { } class program { static stopwatch sw_timer = new stopwatch(); const int num = 100000; static int? testinttype; static testclass testclass = new testclass(); static void main() { console.writeline("值类型测试."); sw_timer.restart(); for (int i = 0; i < num; i++) { object obj = i + 1; if (obj is int) { testinttype = (int?)obj1; } } sw_timer.stop(); console.writeline("is运算{0}次所需时间,{1}ticks.", num, sw_timer.elapsedticks); sw_timer.restart(); for (int i = 0; i < num; i++) { object obj = i + 1; testinttype = obj as int?; if (testinttype != null) { } } sw_timer.stop(); console.writeline("as运算{0}次所需时间,{1}ticks.", num, sw_timer.elapsedticks); console.writeline("引用类型测试."); sw_timer.restart(); for (int i = 0; i < num; i++) { object obj = testclass; if (obj is testclass) { testclass objtest = (testclass)obj; } } sw_timer.stop(); console.writeline("is运算{0}次所需时间,{1}ticks.", num, sw_timer.elapsedticks); sw_timer.restart(); for (int i = 0; i < num; i++) { object obj = testclass; testclass objtest = obj as testclass; if (objtest != null) { } } sw_timer.stop(); console.writeline("as运算{0}次所需时间,{1}ticks.", num, sw_timer.elapsedticks); console.readkey(); } }
测试结果
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论