Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populate a Dictionary
Message
De
23/03/2011 10:17:58
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01504070
Message ID:
01504656
Vues:
54
>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



>>
>>
Dictionary<string, string> MyDictionary = ds.Tables[0].AsEnumerable().ToDictionary(dr => dr["KeyName"].ToString(), dr => dr["KeyValue"].ToString());
>>>Hi Rob, I don't see ToDictionary() in intellisense - is it a VS2010 thing ?

>>
>>Pete, it was available in VS2008 also. You probably don't have the proper using: using System.Linq;
>
>
>
>Hi Bonnie , now I have that sorted - how can I populate a "List<string>" using a similar method ?
>
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform