RSSAmplifier

Andraž Bajt's blog · Jan 27, 2013

Null-coalescing(??) in scala

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

I was doing my homework today(yes I am aware I should be enjoying myself on 30th December) and had some problems with concatenating possibly null strings in LINQ . Quick trip to StackOverflow and I find out C# has some funky operators that solve this in a (sort-of) clean way. 1 var outputString = input1 ?? '' + input2 ?? '' ; I like type inference so I use var’s extensively - please…

I was doing my homework today(yes I am aware I should be enjoying myself on 30th December) and had some problems with concatenating possibly null strings in LINQ. Quick trip to StackOverflow and I find out C# has some funky operators that solve this in a (sort-of) clean way.

1
var outputString = input1 ?? "" + input2 ?? "";

I like type inference so I use var’s extensively - please don’t judge me. What this does is concatenate input1 and input2 substituting null values with empty string. In scala you would write something like

Read on /posts/2013-01-27-null-coalescing/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.