Hi,
>NOW I am in other web form and I NEED to recover the object saved in session like this;
>
>? Mylocalcollection;
>Mylocalcollection = Session[“mycollection”];
>
>?= the type I don’t know.
>
>BUT, I need first to declare the type of Mylocalcollection which is unknown, since I can have several types of object saved into the session (each table of my system represents a type). If I don’t know the type I can not initialize my local object.
>
>How can I solve this situation with generics or whatever.
Maybe something like:
object o = Session[“mycollection”];
string s = o.GetType().ToString();
switch (s)
{
case "PossibleTypeA":
{
PossibleTypeA x = (PossibleTypeA)o;
break;
}
}
>Note: This is solved in C# with the type VAR, but for now I am in C# 2
Not so I'm afraid. The type of var has to be resolvable at compile time.
HTH,
Viv