I suppose method call chain below.
void DoSomething() { ObjectA a = CreateA(); if (a != null) { a.Foo(); } } ObjectA CreateA() {
If you are using C# 6.0 or higher, you got an easy solution with Null conditional operators for this issue.
see this link
https://msdn.microsoft.com/en-au/library/dn986595.aspx?f=255&MSPPError=-2147217396&cs-save-lang=1&cs-lang=csharp#code-snippet-1