Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populate a Dictionary
Message
 
À
18/03/2011 15:33:02
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:
01504205
Vues:
54
>>Try the following:
>
>Dictionary<string, string> MyDictionary = ds.Tables[0].AsEnumerable().ToDictionary(dr => dr["KeyName"].ToString(), dr => dr["KeyValue"].ToString());
>
>

>Excellent suggestion, Rob ... I wanted to mention an additional syntax one could use to cover the situation where your KeyValue, and thus the item in your dictionary, may not be a string:
>
>
>Dictionary<string, int> MyDictionary = ds.Tables[0].AsEnumerable().ToDictionary(dr => dr.Field<string>("KeyName"), dr => dr.Field<int>("KeyValue"));
>
>
>~~Bonnie


Hi All, thanks for all your suggestions I will post back when I decide what to do - who wrote LINQ ? what were they on ?
Regards,
Peter J. Kane



Pete
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform