Results 1 to 6 of 6

Thread: [RESOLVED] Class Member Variables Naming Convention

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Resolved [RESOLVED] Class Member Variables Naming Convention

    Microsoft recommends using something like below for your class naming conventions.

    VB Code:
    1. public class Customer
    2. {
    3.     string name;
    4.  
    5.     public string Name
    6.     {
    7.       set
    8.       {
    9.         name = value;
    10.       }
    11.          
    12.       get
    13.       {
    14.         return name;
    15.       }
    16.     }
    17. }

    Does anyone know why Microsoft wanted to get away from using the m_? It makes it a bit easier to read and know if you see that m_ it is a class variable.

    VB Code:
    1. public class Customer
    2. {
    3.     string m_name;
    4.  
    5.     public string Name
    6.     {
    7.       set
    8.       {
    9.         m_name = value;
    10.       }
    11.          
    12.       get
    13.       {
    14.         return m_name;
    15.       }
    16.     }
    17. }

    Your thoughts please?
    This space for rent...

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,454

    Re: Class Member Variables Naming Convention

    The idea is to use names that describe the data, not the variable. The IDE can tell you what you need to know about the variable by mousing over it. Personally, I always qualify my member variables with 'Me' (VB) or 'this' (C#) when I use them anyway. Most of what I've read on MSDN suggests that what convention you use for private variables is of little consequence anyway. They are more concerned with the public interface and that it conforms to what's used in the rest of the Framework.

  3. #3
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Re: Class Member Variables Naming Convention

    comming from VB6 and using hungairan notation I found it hard to move way from at first, but now making sure i use more discriptive names for the object(varibale) makes more sence. the following document gives a good account of coding style in .Net focusng on C#

    Conding style

    Hope this helps!!!

  4. #4

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Re: Class Member Variables Naming Convention

    Thanks for the replies. For right now I'll stick with the using the first example.
    This space for rent...

  5. #5
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: Class Member Variables Naming Convention

    I find it's nice to have private class variables prefixed w/ an underscore - it's a nice heads up re: what you're using.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,956

    Re: Class Member Variables Naming Convention

    I use the _ method too for private variables. That way I know for sure if I'm accessing the variable directly or through the property.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width