I was looking at the mvc-mini-profiler developed by the Qaru team in Google Code, and one thing at the beginning of my work is especially strange:
var profiler = MiniProfiler.Current; // it ok if this is null using (profiler.Step("Set page title")) { ViewBag.Title = "Home Page"; }
How can this be “normal” if the profiler is null? It seems to me that calling Step will NullReferenceException . For all the years of C # programming, I never called a method on a null reference in any context "good." Is this a special case in the context of a usage proposal?
I can understand that this is OK (I didn’t know what it was, but apparently this is so?):
using (null) { ... }
but calling the method in a null reference seems like it should throw an exception, regardless of whether it is in the use clause. Can someone explain how such a design is broadcast backstage, so I can understand why this is normal?
null c # nullreferenceexception
Jake petroules
source share