?
Solved

static variables

Posted on 2004-09-01
5
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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