Everyone knows at least two common C # idioms, including the coalesce operator:
singleton:
return _staticField = _staticField ?? new SingletonConstructor();
and chain:
notNullableResult = nullable1 ?? nullable2 ?? nullable3 ?? default(someType);
it is readable, consistent, deserving of use and recognizable in code.
But, unfortunately, thatโs all. Sometimes he needs to expand or change. Sometimes I use them when I see a specific case, and I always hesitate to use it because I donโt know if any other programmer will really read it easily.
Do you know others? I would like to have more specific uses: for example. Asp.net, EF, LINQ, everything where the union is not only acceptable, but also wonderful.
c # null-coalescing-operator
rudnev
source share