O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Null-Conditional Operators

One of the most repetitive tasks you do as a programmer is to check a value for null before you work with it. The code to do this checking is typically all over your application. For example, the following verifies whether properties on an object are null before working with them. (For a more complete discussion of all operators, see the section “Understanding Operators” later in this chapter.)

C#

public bool IsValid(){    if (this.Name != null &&        this.Name.Length > 0 &&        this.EmpId != null &&        this.EmpId.Length > 0)    {        return true;    }        else    {        return false;    }}

VB

Public Function IsValid() As Boolean    If Me.Name ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required