Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 12th, 2007, 12:41 PM   #1
alphonso
Programmer
 
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3 alphonso is on a distinguished road
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
alphonso is offline   Reply With Quote
Old May 12th, 2007, 4:11 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 lectricpharaoh will become famous soon enough
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
lectricpharaoh is offline   Reply With Quote
Old May 12th, 2007, 4:20 PM   #3
milot
Programmer
 
milot's Avatar
 
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0 milot is on a distinguished road
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.
milot is offline   Reply With Quote
Old May 12th, 2007, 10:19 PM   #4
alphonso
Programmer
 
Join Date: Dec 2005
Location: Philippines, where the seasons are: hot, and hotter
Posts: 72
Rep Power: 3 alphonso is on a distinguished road
I see. Thanks for all your help
__________________
"The most incomprehensible idea about the universe is that it is comprehensible" - Albert Einstein
alphonso is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC