Lets look at below example, In here, we have declared an Employee class. expression2 ( This expression evaluates to expression2, if expression1 is Not-Null. It uses a question mark ? and member access operator. Syntax and usage of null conditional operator (?.) : This operator (?.) verifies null ability of the operand before calling the method or property. To address the run-time null reference exception issue and to reduce the duplicate code for each null check, C#6.0 introduced null-conditional operator (?.). In-that situation you have to write explicit null-ability check of the object before invoking method or property. In that case, run-time throws a Null Reference exception. In some situations, whenever you invoke a method or property on a object that is NULL. Null conditional operator (?.) is another useful addition made to C# 6.0, it allows developers to write cleaner and concise code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |