We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

sophtwarez on 07/29/06


Tagged

database generics c


Versions (?)


Generics with Databinding


Published in: C# 


URL: http://hobbitwerk.brinkster.net

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


  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. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: ixia on February 7, 2008

The calling code needs to know what datatype the two columns returned are... This would be ok in a data access layer, but personally I would not even do it there.

You need to login to post a comment.