By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,210 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,210 IT Pros & Developers. It's quick & easy.

Diclaring class level variable

P: n/a
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 .

Jan 25 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 25 '07 #2

P: n/a
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

"chandu" <na*************@hotmail.comschrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP06.phx.gbl...
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 .

Jan 25 '07 #3

P: n/a


public class Foo
{
private string foobar; <---- class level variable or local by
your definition?
}


On Jan 24, 10:53 pm, "chandu" <nareshv_chan...@hotmail.comwrote:
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 .
Jan 25 '07 #4

P: n/a
chandu <na*************@hotmail.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 25 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.