Solved

static variables

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

15 Experts available now in Live!

Get 1:1 Help Now