Tuesday, June 19, 2012

We can remove duplicate entries by using ".Distinct()" in arraylist

We can remove duplicate entries  by using ".Distinct()" in arraylist


I have createdby column exist in testtable which have more one row exist with 5 duplicate entries. i have to get only one row

   ID   Createdby
    ===  ========
      1    Reddy
      2    Reddy
      3    Reddy
      4    Reddy

In above thing i need to select only one "Reddy"

DataTable table=new DataTable("MyTable");//Actually i am getting this table data from database

DataColumn col=new DataColumn("Createdby");

var  childrows =  table.AsEnumerable().Select( row => row.Field<object>(col)).Distinct().ToArray();

No comments:

Post a Comment