Tags: code, explanation, net, objects, prefix, prefixed, sharp, underscore, variables

underscore prefix

On .Net » .Net C# (C sharp)

4,752 words with 4 Comments; publish: Wed, 21 May 2008 22:27:00 GMT; (10047.12, « »)

A few times when looking at code on the net I have seen objects,

variables etc prefixed by an underscore. But I've never seen any

explanation for the reason for this. What is the reason for doing this?

Thanks,

Mike

*** Sent via Devdex http://www.devdex.com ***

Don't just participate in USENET...get rewarded for it!

All Comments

Leave a comment...

  • 4 Comments
    • This is olb naming convention for private variables. In new MS naming

      convention you should use m_ as prefix for private members

      More information can be found here

      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnamingguidelines.asp

      or use FxCop to validate

      http://www.gotdotnet.com/team/fxcop/

      --

      Tamir Khason

      You want dot.NET? Just ask:

      "Please, www.dotnet.us "

      "mike parr" <mparr_1972.net-csharp.itags.org.yahoo.co.uk> wrote in message

      news:Oxr9EmmYEHA.3664.net-csharp.itags.org.TK2MSFTNGP12.phx.gbl...

      > A few times when looking at code on the net I have seen objects,

      > variables etc prefixed by an underscore. But I've never seen any

      > explanation for the reason for this. What is the reason for doing this?

      > Thanks,

      > Mike

      >

      >

      > *** Sent via Devdex http://www.devdex.com ***

      > Don't just participate in USENET...get rewarded for it!

      #1; Wed, 21 May 2008 22:28:00 GMT
    • Nothing magical about it; it's just one of many naming conventions for

      private class members. I think the underscore prefix is favored by C++

      coders.

      --Bob

      "mike parr" <mparr_1972.net-csharp.itags.org.yahoo.co.uk> wrote in message

      news:Oxr9EmmYEHA.3664.net-csharp.itags.org.TK2MSFTNGP12.phx.gbl...

      > A few times when looking at code on the net I have seen objects,

      > variables etc prefixed by an underscore. But I've never seen any

      > explanation for the reason for this. What is the reason for doing this?

      > Thanks,

      > Mike

      #3; Wed, 21 May 2008 22:30:00 GMT
    • I think prefixing any variable in a strongly typed environment simply adds

      clutter. I find the convention of capitalizing public members but not

      private is much more elegant. Just my opinion.

      Mike

      "Rakesh Rajan" <RakeshRajan.net-csharp.itags.org.discussions.microsoft.com> wrote in message

      news:F8C42234-A091-4C49-A769-3F706F4D6FF1.net-csharp.itags.org.microsoft.com...

      > Hmm...I have always been in the opinion that whenever we have an exposed

      member like a public variable or property etc, we should avoid Hungarian

      Notation and prefixes of any type. But for private entities, I would use m_

      or a prefix...

      > --

      > Rakesh Rajan

      >

      > "Scott Allen" wrote:

      > > I think the guidlines actually discourage use of m_ when it says "Do

      > > not apply a prefix to field names or static field names."

      > >

      > > --

      > > Scott

      > > http://www.OdeToCode.com

      > >

      > > On Mon, 5 Jul 2004 11:40:41 +0300, "Tamir Khason"

      > > <tamir-NOSPAM.net-csharp.itags.org.tcon-NOSPAM.co.il> wrote:

      > >

      > > >This is olb naming convention for private variables. In new MS naming

      > > >convention you should use m_ as prefix for private members

      > > >More information can be found here

      > >

      >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/h

      tml/cpconnamingguidelines.asp

      > > >or use FxCop to validate

      > > >http://www.gotdotnet.com/team/fxcop/

      > >

      > >

      #4; Wed, 21 May 2008 22:31:00 GMT