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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:45 AM EDT
string Name;
if(Session["user"]!=null)
{
name=(string)Session["user"];
}
Regards,
Iftikar
VulpesRank #55 · 29.2K reputationPosted Jul 31, 2013, 2:48 AM EDT
iswarya chandran67 reputationPosted Jul 31, 2013, 3:15 AM EDT
if i give like this i got an compilation error in if condition variable.. as checking unassigned local variable
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 3:18 AM EDT
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 chandran67 reputationPosted Jul 31, 2013, 4:04 AM EDT