Return to Snippet

Revision: 679
at July 29, 2006 08:45 by sophtwarez


Initial Code
public static Dictionary<X, G> BuildDictionary<X, G>(string db, string keyColumn, string valColumn) {
            Dictionary<X, G> myDictionary = new Dictionary<X, G>();
            SqlDataReader rd = new SqlCommand().ExecuteReader();
            while (rd.Read()) {
                myDictionary.Add((X)rd[keyColumn], (G)rd[valColumn]); // ? good idea?
            }
            rd.Close();
            return myDictionary;
        }

Initial URL
http://hobbitwerk.brinkster.net

Initial Description
Methinks this is a bad idea but it is a suggested use of generics from the .NET 2.0 Generics Wrox book

Initial Title
Generics with Databinding

Initial Tags
database, c

Initial Language
C#