Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populate a Dictionary
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Populate a Dictionary
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:
01504070
Vues:
116
Hi All, just in the middle of a code review and I'm finding lots of methods in different classes that use the following method for populating Dictionary and List objects - I'm wondering if there is an easier / generic way using Linq ( It looks like a black art to me ) this is what I have at present
DataSet ds = SomeMethodThatReturnsADataSet("MyDS");
Dictionary<string,string>  MyDictionary = new Dictionary<string,string>(StringComparer.CurrentCultureIgnoreCase);

foreach(DataRow dr in ds.Tables[0].Rows)
    MyDictionary.Add(dr["KeyName"].ToString(),dr["KeyValue"].ToString());
which is pretty basic and clean but , this code is scattered among dozens of classes - any thoughts very welcome
Regards,
Peter J. Kane



Pete
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform