Here’s what I’m trying to do. Have a use right a sequence of numbers delimited by spaces. After I save those numbers, I want to return a string of all the numbers only once, even if a number has appeared n number of times in the sequence.
string[] tempNumbers = textValue.Split(' ');
IEnumerable<string> distinctNumbers = tempNumbers.Where(value => value.Distinct());
I’m getting this error:
Error 2 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<char>' to 'bool' c:\users\sergio\documents\visual studio 2010\Projects\LinqPlayground\LinqPlayground\SetSemanticsExample.cs 67 75 LinqPlayground
The extension method
IEnumerable.Distinctis not a predicate function. It operates on anIEnumerable<T>and returns a newIEnumerable<T>where each element appears only once.To fix your code just do this instead:
If you want the result as a single space-separated string then in addition to the above you will also need to call
string.Join: