Solved

static variables

Posted on 2004-09-01
5
212 Views
Last Modified: 2010-04-15
Can anyone explain this........................................

Static variables declared within nonshared methods are per instance: each instance of the type that contains the method has its own copy of the static variable.

I need to create static variables per instance..... in my application... is it possible... Please let me know?

thanks,
Lakshman

0
Comment
Question by:lakshmankoneru
  • 3
5 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11958181
yeah you are reading the VB.NET help for static ...

out of curiosity isnt a static variable scoped to an instance really an instance variable ?

public class foo {
    private int bar;

    public void test() {
         bar += 1;
    }
}

this would be scoped to the instance no ?
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11958235
in vb.net you can say

public function foo() as integer
    Static var As Integer
end function

and it will have the behavior you describe above ...

but you can get nearly identical behavior by saying

public class class2
    private var as integer

    public function foo() as integer
        end function
    end function
end class
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11958262
see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxorilanguageequivalentskeywords.asp

under Misc. Lifetime (second chart from bottom) no C# equivalent ... mostly for the reasons shown.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

22 Experts available now in Live!

Get 1:1 Help Now