I just started using the safe navigation operator in C# for the first time and I am wondering wether this is a correct use case for that operator:
public bool HasAttributes
{
get
{
return this.SomeClassMember?.Attributes?.Count > 0;
}
}
Why exactly does this code not give me a compiler error? I thought that the result would be null if for example this.Notification
or this.Notification.Attributes
would be null, but return null
on the other hand does not work as it does not seem to implicitly convert to false. If I am not using the operator correctly here, could someone explain how I use it correctly in my use case?