dennisdoomen / CSharpGuidelines

A set of coding guidelines for C# 9.0, design principles and layout rules for improving the overall quality of your code development.
https://www.csharpcodingguidelines.com
Other
745 stars 272 forks source link

AV1545: Add example for null-conditional operator #102

Closed bkoelman closed 7 years ago

bkoelman commented 7 years ago

The null-conditional operator enables shorter syntax. For example:

if (employee.Manager != null)
{
    return employee.Manager.Name;
}
else
{
    return null;
}

can be rewritten as:

return employee.Manager?.Name;