Generics with Databinding


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. public static Dictionary<X, G> BuildDictionary<X, G>(string db, string keyColumn, string valColumn) {
  2. Dictionary<X, G> myDictionary = new Dictionary<X, G>();
  3. SqlDataReader rd = new SqlCommand().ExecuteReader();
  4. while (rd.Read()) {
  5. myDictionary.Add((X)rd[keyColumn], (G)rd[valColumn]); // ? good idea?
  6. }
  7. rd.Close();
  8. return myDictionary;
  9. }

URL: http://hobbitwerk.brinkster.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.