Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate a Dictionary
Message
 
To
All
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Populate a Dictionary
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01504070
Message ID:
01504070
Views:
115
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
Next
Reply
Map
View

Click here to load this message in the networking platform