473,382 Members | 1,349 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,382 software developers and data experts.

what is the difference in declaring this way

375 256MB
Hi,
I have seen many times when variable are declared as
int _qty;

instead of plain
int qty;

Is there any coding preference or rules or any advantage in declaring this way i.e. using _ symbol

Regards
cmrhema
Apr 17 '09 #1
5 1224
Sl1ver
196 100+
variable has to 1 word
Apr 17 '09 #2
tlhintoq
3,525 Expert 2GB
I think most people just use the underscore to indicate the non-public reference of a value.

Expand|Select|Wrap|Line Numbers
  1. private int _score = 5; // gives a default value
  2. public int Score
  3. {
  4.      get { return _score;}
  5.      set { _score = value;}
  6. }
Its kind of like prefacing variable names with a letter to indicate their type:

int nScore;
bool bEnabled;
string szName;
Apr 17 '09 #3
artov
40
For coding preferences, you might like to try Microsoft's StyleCop and FxCop.

StyleCop recommends to drop the underlines, btw,
Apr 20 '09 #4
tlhintoq
3,525 Expert 2GB
@artov
Interesting. I have a long flight. This will give me something interesting to check out. Thanks!
Apr 20 '09 #5
r035198x
13,262 8TB
There may be rare circumstances when you need to edit code (say add a value in the session) and want to guarantee that the variable name you choose does not clash (and thus hide) an already existing variable name.
Such circumstances are rare and generally you will want to stay away from such evil nomenclature.
Apr 20 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Thomas | last post by:
I tried the following: Public Class ClassA Public Class ClassB Private myName As String Private myBirthday As Date Public Property Birthday() As Date Get Return myBirthday
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
12
by: TC | last post by:
I'm trying to figure out what the "Friend" keyword does. I know it specifies that "elements are accessible from within the same assembly", but that doesn't help because I don't know what an...
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
1
by: prisesh26 | last post by:
What is the difference between declaring a member variable as final static and static final? thanks
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.