0

I have a data table like below. Say I have thousands of records:

+----------------------+
| Col1          | Col2 |
+----------------------+
| Value1        | 1    |
| Value1,Value2 | 2    |
| Value2        | 3    |
| Value3,Value1 | 4    |
+----------------------+

Col1 can have a single value or value which is delimited by a special character (e.g. ",").

I would like get the distinct values from Col1 in a single LINQ query. I can do this in two steps, but I want it to be done in one step.

Can this be done, either as a list or an array?

4

1 回答 1

3

I think this will work.

var array = table
    .SelectMany(t => t.Col1.Split(','))
    .Distinct()
    .ToArray();
于 2012-09-04T19:48:29.440 回答