Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

... and this is so wonderful! It's in no way worse than the ternary operator. You punt to a default value really easily, without having 20 lines of `if (a.this == null) a.this == 0; if(a.that == null)a.that == ""` or similar.

When constructing objects "in-line" in c# I actually used to see the ternary operator quite a lot, as in

  new SomeClass() {
    Val = valSource == null? SomeClass.DefaultVal : valSource
  }
The coalesce operator is way better. Except it can't be used in LINQ projections.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: