In SQL to get the DISTINCT values in a column I would do something like:
SELECT DISTINCT ColumnName FROM TableName;
I would like to do something like this but for a DataTable's DataColumn. I am aware of this way (follow this link) which does the usual intuitive way of using the fact that we can check if what we have Contains(whatWeWant) or not, and if it doesn't we can add it to some container of unique items. What I would like to know is if there is something like the following out there:
var uniqueObjects = dataTable.Columns[0].Distinct().ToList();
I am also aware from reading the Microsoft Docs that the DataColumn class does not have a method called Distinct but if there is something like this that you guys are aware of please let me know. If not I will resort to making a Distinct extension method with the intuitive way of using Contains.
If you add System.Data.DataSetExtensions
to your project's references:
using System.Data;
var uniqueObjects = dataTable
.AsEnumerable()
.Select(row => row[0])
.Distinct()
.ToList();