Using Linq DefaultIfEmpty() extension method
For example
1
2
| var numbers = new int [] {1,2,3,4,5,6,7}; Console.WriteLine(numbers.DefaultIfEmpty(). Sum ()); |
By Default if you want to return some value other then 0 it will return that as well
1
| Console.WriteLine(numbers.DefaultIfEmpty(100). Sum ()); |
0 comments:
Post a Comment