Properties in a Class

Posted on 2014-07-11
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:BobCSD
    LVL 74

    Accepted Solution

    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

    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.
    LVL 1

    Author Comment

    okay, that's what I was trying to remember. How that happened in the past. It was a static variable. thanks!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now