473,785 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3859
>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.comsc hrieb im Newsbeitrag
news:%2******** *******@TK2MSFT NGP06.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.comwr ote:
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.comwr ote:
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.co m>
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
2481
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 __init__(self): self.x = 2 >>> r = rectangle() >>> print r.z
4
1499
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 Date::default_date(16, 12, 1770); In the following code.
166
8677
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
1680
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 aspx codebehind module I can define my object right after the class definition as so: dim myDBComp as DBComp The problem I had was where to put the instantiation:
13
1887
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 in what would make it better. If I have totally missed on what a class is used for please inform me. Thanks, Thomas
19
4921
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 exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
3
1300
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 an MDI tabbed environment. So when a new MDI child form is displayed, a new tab is created much like VS.NET 2005 development environment. Is it best to dimension a new SQL wrapper class at the module level of a child form, or should I be...
2
1936
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 = System.Web.HttpContext.Current.Session.Item("mySessionVar") But I can't figure out if it is possible to access a page level variable from within a class.
1
25700
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 bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.