![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3
![]() |
Underscores in a field?
Hi
I seem to run into code from books wherein the name of a field in either a struct or a class is prefixed with an underscore. What does this mean? The books don't explain them. I knew for one thing that it couldn't have been naming convention, because they always advise NEVER EVER use underscores when it comes to naming fields, methods, properties, etc. Can anyone help me, please? Here's an example: class Order
{
private Int _orderID;
private ArrayList _orderItems;
public int OrderID;
{
get {return _orderID;}
set {_orderID = value;}
}
...
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,033
Rep Power: 5
![]() |
You'll notice the underscores are for the private class variables. Another common convention is to use things like m_orderID for private variables; I myself prefer a simple leading underscore, as in your example code. The idea here is that only the person(s) who implemented the class will see these names. The class's externally-visible (public, as well as protected, internal, and protected internal) members probably should not be named this way, but I'm not aware of any language rule this would violate (it's simply a convention).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0
![]() |
Hi,
It's not anything special but in C# it allows you to use underscore in front of a variable followed by letters (or numbers), but it is not very recommended because it sometimes is hard to read but it can used for special commands, at least some programmers practice this method, but I'm not still used to it but I'm trying. I use variables like my_var but not as _my_var. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3
![]() |
I see. Thanks for all your help
![]()
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sorting an array by field | cwl157 | C | 4 | Apr 4th, 2007 2:48 PM |
| Field Validators inside a User Control | hoffmandirt | ASP.NET | 5 | Jun 30th, 2006 2:52 PM |
| To find a local minimum in a field | alejandrito | C | 2 | Dec 12th, 2005 10:36 AM |
| retrieve field name from SQL server 2000 | maxchin | C++ | 2 | Oct 13th, 2005 12:40 AM |
| Structure char field to a disk file | ehab_aziz2001 | C++ | 0 | Feb 10th, 2005 2:42 PM |