473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Diclaring class level variable

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
4 3837
>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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Munroe | last post by:
I am just starting to learn the OO side of Python scripting, and I am a little confused on the following. Take the following example class: >>> class rectangle(object): z = 1 def...
4
by: Fao, Sean | last post by:
Hello All, I'm reading The C++ Programming Language and I'm having a misunderstanding of part of the code in the book. Specifically, I'm not understanding the line: Date...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
4
by: Dean | last post by:
I finally got class session variables to work by putting the following in global.asax in the session_start: dim myDBComp as DBComp = new DBComp........ session("myDBComp") = myDBComp In each...
13
by: thomasp | last post by:
I have written my first Class and am posting it to this newsgroup with hopes that I can get some feedback on what is right and what is wrong with it. All comments are welcome, but more interested...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
3
by: Scott H. | last post by:
I have aVB.NET application that uses an SQL Server wrapper class to connect and perform any and all ADO.NET database activities. This is an MDI child based application where the child forms are in...
2
by: Corey B | last post by:
Is there a way for an instance of a custom class to access an ASPX page level variable? I know that I can access a Session variable from within a class using the following code: myClassVar =...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.