cast String to objet of class
-
Hi, i have to convert string to class object in c#. Class Admin = new Admin(); if(!((Admin)Session["Admin"]).GetRight()) { } i have to convert session["Admin"] to class Admin Object.. its give an error at runtime (can't convert string to class object) Any Solution..
-
Hi, i have to convert string to class object in c#. Class Admin = new Admin(); if(!((Admin)Session["Admin"]).GetRight()) { } i have to convert session["Admin"] to class Admin Object.. its give an error at runtime (can't convert string to class object) Any Solution..
First thing find the code which is actually populating this
Session["Admin"]
. make sure that it is puttingAdmin
type into it and not somestring
only. Secondly - use this to call the functionAdmin ad = Session["Admin"] as Admin;
if(ad != null) //you have the right thing
{
if(ad.GetRight())
{
//go further
}
}
else
{
//something wrong with session value do some corrective thing.
}Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.