On 14 Jan 2007 14:39:38 -0800, "Marc Gravell" <(E-Mail Removed)> wrote:
>Consider your line:
>T t = new Dictionary<string, DxccCountry>();
>
>Now; if <T> is <int>, this reads:
>int t = new Dictionary<string, DxccCountry>();
>(and then presumably "return t").
>
>Which clearly isn't going to work. Only valid casts are legal. If you
>know it will cast at runtime, sometimes you need to cast (/box) to
>object and back for this to work. However, the above clearly never will
>work.
>
>If you mean to return a dictionary, then perhaps something like:
>
>Dictionary<string, T> dict = new Dictionary<string, T>()
>
>etc. Other options include adding "where" clauses etc to the type of T,
>or using interfaces etc. If you can expand on what you want, we can
>help clarify.
>
>Marc
Thanks, Guys.
I think I must be taking the wrong approach to doing what I want.
I have a class named CountryTable:
public class CountryTable
{
....
}
Which I want to use to call stored procedures from a database for a table Named
"CountryTable". I want to have methods in the class name Select, Update, Delete
and Insert.
The reason I am trying to use generics for this is to reduce the amount of code
I have to write, since I have many more tables that I want to access in this
manner.
I could use overloaded methods to do this but if I make a Select method with the
following signature:
public Dictionary<string, DxccCountry> Select();
I have used up my overloads for that method.
I was hoping I could use a generic return to avoid passing a parameter to avoid
compiler errors. I could do this to accomplish the overloading:
public Dictionary<string, DxccCountry> Select(Dictionary<string, DxccCountry>
countries)
{
// do some stuff
return countries;
}
and then :
public List<DxccCountry> Select(List<DxccCountry> countries)
{
//do some stuff
return countries;
}
IMHO that's not good practice.
I guess my trouble here is not knowing how to implement the abstract method from
the DataMethod class.
What I was hoping to end up with was something like this in the caller:
CountryTable tbl = new CountryTable();
Dictionary<string, DxccCountry> countries = tbl.Select();
Obviously I missed the mark somewhere on the way ;o)
Good luck with your project,
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com