Solved

static variables

Posted on 2004-09-01
5
214 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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