检查空的性能损失 [英] Performance hit of checking for null
问题描述
谁能告诉我的性能开销,如果检查对象的对象或属性在C#中为null什么?我的工作在该空检查是模型正在做,然后在视图中再次做了一个ASP.NET MVC应用程序。我觉得这是过分的,但如果然后打没有真正的表现,我不看做事这种方式的危害。
Can anyone tell me what the performance cost is of checking if an object or property of an object is null in c#? I am working on an ASP.NET MVC application that the null checking is being done in the Model and then done again in the view. I feel that this is excessive but if there is no real performance hit then I don't see the harm in doing things this way.
推荐答案
我不,如果你这样做只是一次在渲染认为它可测量的,一旦在初始化模式。
I don't think its measurable if you're doing it just once while rendering and once while initializing the model.
这将产生影响,如果它是虽然计算密集的循环中。
It would have an impact if it were inside a computation-intensive loop though.
像查询数据库的东西,读/写文件等都是你应该提防。的那些
Things like querying the database, read/write to files, etc. are the ones you should watch out for.
这篇关于检查空的性能损失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!