Gotcha C# operator

Sometimes I have a positive feeling of “what’ta f…” reading someone else code (at a contrary to negative feeling of the same sort wchich I get way to often). Recenty I’ve found the ?? operator in C#. And really I didnt know it could by used it this way:

            string s = null;
            string s2 = s ?? "remembered";
            string s3 = s2 ?? "vorgotten";

The ?? operator returns the left operand if it not equalls null and the right one when it is. Simple and usefull!

Leave a Reply

Your email address will not be published. Required fields are marked *