Diclaring class level variable

  • Thread starter Thread starter chandu
  • Start date Start date
C

chandu

Hello,

declaring class level variables is good approach or not in c#.

in C++ we used prefer diclaring class level variables more than local
variables.

i had a discussion with somebody that in C# it is disadvantage to diclare
class level variables

so clarify it .
 
in C++ we used prefer diclaring class level variables more than local
variables.

Why? Usually, you pick as narrow scope as possible to prevent
accidental use of variables.


Mattias
 
Hi chandu,

you are comparing very different things. Local variable and class level
variables simply have different meanings. Could you give me an example,
where a local variable could be used instead of a class level variable? I
can't think how this is possible.

Christof
 
public class Foo
{
private string foobar; <---- class level variable or local by
your definition?
}
 
chandu said:
declaring class level variables is good approach or not in c#.

in C++ we used prefer diclaring class level variables more than local
variables.

i had a discussion with somebody that in C# it is disadvantage to diclare
class level variables

so clarify it .

It's a bit like asking whether you should use a file or a database - it
entirely depends on what you're doing. If something is naturally part
of the state of the class, it can't be a local variable. If it isn't
part of the state, it shouldn't be a class variable.
 
Back
Top