Properties in a Class

Just to confirm...

I have a class. in the class I define a value by default.

Dim ClientId as integer = 5

When a user logs in an uses the class they can change the clientid to something else, perhaps 7.

Once the one user changes it to 7, and another user logs in, the new user will still get 5 won't they? Or will they get 7 because I didn't create it as a session property?

thanks!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
 
käµfm³d 👽Commented:
Yes, the second user will get 5. This is because your class will be instantiated each time a request comes in. Instance fields are always reinitialized when an instance is created.

Now, if the value were static things could be different. But it's rare that you would want to mark a variable as static in a web app.

Session applies to each user. So even if you stored the updated value to a session variable, the second user would not see 7 because the second user cannot see the first user's session.
0
 
MajorBigDealCommented:
Yes, the new user will still get 5, not 7.  

The new user could get a changed value if you were storing an instance of the class (not the class itself)  in a place where both users could access it, such as an application property, or a database, or something like that.

But in the circumstance you described that would not happen.
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
okay, that's what I was trying to remember. How that happened in the past. It was a static variable. thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.