Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Session Boolean Set Get Syntax?

Posted on 2012-04-11
3
Medium Priority
?
266 Views
Last Modified: 2012-04-11
I'm always looking for ways to shorten code while still maintaining function.

Q. Is there any functional difference between the two examples concerning set/get boolean in a Session?

[store boolean value]
   bool IsLightOn = true;
   Session["IsLightOn"] = IsLightOn;  

[get boolean value]
   bool IsLightOn;  
   if (Session["IsLightOn"] != null)  
       IsLightOn = (bool)Session["IsLightOn"];

- or -

[store boolean value]
   Session["IsLightOn"] = true;  

[get boolean value]
   if (Session["IsLightOn"] != null)  
       bool IsLightOn = (bool)Session["IsLightOn"];
0
Comment
Question by:pointeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 1000 total points
ID: 37832405
No there is no difference, in both the cases bool is boxed at the time of entering into session and unboxed when it is retrieved.
The only difference is however you are using a variable to store bool to session in first case.

You should ideally declare a variable if you know you are going to use it more than once in you code....
In your case Session["Value"]=true would be good enough;
0
 
LVL 2

Expert Comment

by:yogsoft
ID: 37833037
Well said @BuggyCoder. Also memory allocation can be avoided for variable in this case.
0
 

Author Closing Comment

by:pointeman
ID: 37833167
Thx, just wanted another EE opinion...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question