Coalesce operator in C#

2007-09-24

    I got reminded about the ??-operator in C# today. It is a coalesce operator and works like this:

    string a = null; string b = a ?? "Woops, a is null."; Console.WriteLine(b); <- Will write 'Woops, a is null.'

    I really need to read the language specification at least one time per year to remind myself about all the things I don’t use frequently. It is way to easy to keep on solving programming problems with the same old tools all the time. I like to learn new languages. At least to the level that I know what to google about if I have to use a specific language. But at the same time I think one should try to master at least one language. C# has been my favorite tool for years so I am blushing a bit as I confess my shortcomings.