static variables in C#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Can you declare a variable as static in C#? If not, then is there a 'module'
level area or eqivelant in C# in which you can do this?

Thanks in advance

Ant
 
Hi Ant

static variable name;


Hi,
Can you declare a variable as static in C#? If not, then is there a 'module'
level area or eqivelant in C# in which you can do this?

Thanks in advance

Ant
 
Hi Morten,
Thanks again.

I tried both these but both were not accepted. This is in a button click
event.

Static int siMyStaticVar; // Error on Static (understandable - s not S)
static int siMyStaticVar2; // Error on int (?)

Thanks again. Getting into C# after VB6. I feel like I've been in an
accident & have lost all my motor skills :)

Cheers
Ant
 
Ant said:
I tried both these but both were not accepted. This is in a button click
event.

Static int siMyStaticVar; // Error on Static (understandable - s not S)
static int siMyStaticVar2; // Error on int (?)

Thanks again. Getting into C# after VB6. I feel like I've been in an
accident & have lost all my motor skills :)

Are you trying to declare these as *local* variables? If so, there's no
direct equivalent to VB's local static variables in C#. Instead, you
need to make the variable part of the class - either as a static
variable or an instance variable, depending on your needs.

The reasoning for this is that a method doesn't logically have state -
only an object (or a type) does.
 
Back
Top