Hi
I just started working with generics and am stuck at a basic problem.
Have a base class - BaseObject
Have 3 derived classes from this - User, Product and Site.
Now, I have a ReturnObject method that returns a generic of BaseObject (List<BaseObject>)
But I really am returning List<User> from this method
This is the code from User.cs:
public List<BaseObject> ReturnObject()
{
//...do something
return List<User>;
}
So my return type is a generic of the base and I actually want to return a generic of the derived class.
Is there any way to do this
Also in my main program.cs, I have
List<User> u = ReturnObject()
The above line gives an error. It says that I cannot assign a generic base to a generic derived object.
Now I want to pass a collection of child and I want to declare the return type as collection of base class.
Is there anyway I can do this
I think I can get this done using arrays, but I would really like to use generics.
Thanks for your help
Rishi...