Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate a Dictionary
Message
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01504070
Message ID:
01504669
Views:
60
>>>Hi Bonnie , now I have that sorted - how can I populate a "List< string >" using a similar method ?
>>
>>Similar to the .ToDictionary(), but you have to include a .Select:
>>
>>
>>List<string> list = ds.Tables[0].AsEnumerable().Select(row => row.Field<string>("MyField")).ToList();
>>
>>
>>~~Bonnie
>
>Whoah - this LINQ stuff is getting interesting - thanks very much for your help


One final ( maybe ) question :-) - I have one routine which loops through a Columns collection of a DataTable and adds the column name as the K and the columns value as the V - could this be achieved with LINQ ? this is how I currently do it
foreach(DataColumn dc in ds.Tables[0].Columns)
    MyList.Add(dc.ToString(),ds.Tables[0].Rows[0][dc].ToString());
Regards,
Peter J. Kane



Pete
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform