ScannerMessages.Values.Distinct().Count(v => !String.IsNullOrEmpty(v))
- You already selected values, thus you already have sequence of strings, and you don't need to try getting value from string with
x.Value
- You should pass string to
String.IsNulllOrEmpty
method to verify if this string is null or empty - You don't need to create list with value from dictionary -
ValueCollection
implementsIEnumerable<string>
thus you can use Linq methods directly (e.g.Distinct
orWhere
) - If you want to count items in sequence which match some condition (i.e. predicate) then instead of usage
Where(predicate).Count()
you can use shortcut - overloadedCount(predicate)
method which takes predicate.