Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance hit of checking for null

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.

like image 934
Jeremy Avatar asked Dec 11 '25 17:12

Jeremy


1 Answers

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.

like image 57
Robin Maben Avatar answered Dec 14 '25 13:12

Robin Maben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!