Is it possible to check the unassigned local variable with if condition??
for eg;
string name;
try
{
name= (string)Session["user"];
}
catch {}
if(name==null)
{
//code we want
}
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
iswarya chandranPosted Jul 31, 2013, 8:04 AM
Iftikar HussainPosted Jul 31, 2013, 7:18 AM
string Name;
if(Session["user"]!=null)
{
name=(string)Session["user"];
}
else
{
//your code
}
or
object Name=Session["user"];
if(Name==null)
{
//your code
}
Regards,
Iftikar
iswarya chandranPosted Jul 31, 2013, 7:15 AM
if i give like this i got an compilation error in if condition variable.. as checking unassigned local variable
VulpesPosted Jul 31, 2013, 6:48 AM
Iftikar HussainPosted Jul 31, 2013, 6:45 AM
string Name;
if(Session["user"]!=null)
{
name=(string)Session["user"];
}
Regards,
Iftikar