Click here to Skip to main content
15,888,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to ask question
is session work by val or by ref
mean if i said
iam working on web site and use linq to sql dbml
i have stored procedure in dbml
for example say my stored procedure called sp
in my c# Code
1- say sesssion["a"]=list<sp>
2- list<sp>.add new row
3- when i look again on my session i find it's value increase
instead of i didn't assign it it again after add the new row
Posted
Updated 21-Aug-11 21:32pm
v2
Comments
sreeparnamaz 5-Sep-12 3:15am    
In my case i am assigning the session in a list. When the list get updated the session also get updated.
List<string> _lstResult = new List<string>();
_lstResult = (List<string>)Session["Result"];
after this any change in the list the change get reflected in the session.
We do not want the session to get updated when the list is modified.How to resolve this issue??

Why don't you simply try it out?

A session stores items as a SessionStateItemCollection.
This, in turn, is a collection of objects.

So I would think items in a session will be reference type.
 
Share this answer
 
Comments
[no name] 22-Aug-11 3:38am    
can i have any way to convert it to value type
Abhinav S 22-Aug-11 3:46am    
You can always use the Convert method in your code to do conversions from object to int etc.
session["a"] will be 1.

As for your updated (second) question, the list in sesssion["a"] will be the same list you added a row to.

Refer to
Value Types (C# Reference)[^]
Reference Types (C# Reference)[^]

If you don't want the list in your session to get the row you add you can do
C#
Session["a"] = new List<...>(list);
 
Share this answer
 
v5
Comments
[no name] 22-Aug-11 3:39am    
i edit my question to be more reality could u look at it again
It is simple enough to try out, if you put this into the page load method:

int x =2;
Session["a"] = x;
x = 3;
var y = Session["a"];

y ends up with the value 2, making items in the Session reference types.
 
Share this answer
 
Comments
[no name] 22-Aug-11 3:41am    
i edit my question to be more reality could u look at it again
becuase the value i assign to session is refernce value

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900