user565992
user565992

Reputation: 497

Linq get the value from the var returned

I have the below code I am getting a distinct value from the datatables and then using the value to select on that datatable.

string ccId = d.ToString(); 

is being returned as "{ id = B08 }" -- I just need B08 how can I get that value?

var distinctIds = dt.AsEnumerable()
                  .Select(s => new { id = s.Field<string>("CCId"),})
                  .Distinct().ToList();



foreach (var d in distinctIds)
{
     string ccId = d.ToString();
     DataTable selectedTable = dt.AsEnumerable()
                            .Where(r => r.Field<string>("CCId") == ccId).CopyToDataTable();
     CreateFile(selectedTable);
}

Upvotes: 0

Views: 42

Answers (1)

Canica
Canica

Reputation: 2738

You are forcing this structure when populating distinctIds. By removing the anonymous (new) call in your select you will have a list of the values only.

var distinctIds = dt.AsEnumerable()
                    .Select(s => s.Field<string>("CCId"))
                    .Distinct().ToList();

Upvotes: 3

Related Questions