Evil use of Maybe monad and extension methods in C#?

前端 未结 8 1847
面向向阳花
面向向阳花 2020-12-07 17:11

edit 2015 This question and its answers are no longer relevant. It was asked before the advent of C# 6, which has the null propagating opertor (?.)

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 17:37

    In case you're dealing with C# 6.0/VS 2015 and above, they now have a built-in solution for null propagation:

    string ans = nullableString?.Length.ToString(); // null if nullableString == null, otherwise the number of characters as a string.
    

提交回复
热议问题