Yeah, it seems odd. Actually, from the help.
"Static variables are locals that retain their value across invocations of
the method. 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. Static variables declared within Shared methods
are per type; there is only one copy of the static variable for all
instances. While local variables are initialized to their type's default
value upon each entry into the method, static variables are only initialized
to their type's default value when the type or type instance is initialized.
Static variables may not be declared in structures."
So it appears that the "staticness" of a Static variable depends on the
"staticness" of the method in which it's declared. Of course, the latter
makes sense.
--
Tim Wilson
..Net Compact Framework MVP
"David" <df*****@woofix.local.dom> wrote in message
news:slrnd4e03m.5af.df*****@woofix.local.dom...
On 2005-03-28, Tim Wilson <> wrote: You'll need to declare a static field (or just a field, depending on
what you need it for) at the class level, and then you can increment the
value in the method.
private static int count = 0;
...
public int Increment()
{
count++;
return count;
}
It's kinda weird, but a closer equivalent is actually:
private int count = 0;
Variables declared Static in VB.Net aren't actually, well, static.
There's one per instance. They're just normal fields with limited scope
and delayed thread-safe initialization.