January 2012
Intermediate to advanced
396 pages
8h 16m
English
Follow the given steps:
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int n = numbers.SingleOrDefault(c => c % 2 == 0 && c % 6 == 0);
n.Dump();Output is 6 because numbers has 2 and 6 and only 6 matches the predicate passed as the argument to the SingleOrDefault() method call.
The following diagram explains how the SingleOrDefault() method behaves in two different situations:
So SingleOrDefault() is just Single() with the default value attached. So, if you think usage of Single() ...
Read now
Unlock full access