Learn how to a build a cloud-first strategyRegister Now


Properties in a Class

Posted on 2014-07-11
Medium Priority
Last Modified: 2014-07-11
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?

Question by:Starr Duskk
LVL 75

Accepted Solution

käµfm³d   👽 earned 1100 total points
ID: 40191311
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.
LVL 11

Assisted Solution

MajorBigDeal earned 900 total points
ID: 40191315
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.

Author Comment

by:Starr Duskk
ID: 40191494
okay, that's what I was trying to remember. How that happened in the past. It was a static variable. thanks!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

810 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