New to C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    New to C#

    Hi All,
    I am switching over from Visual Basic (actaully VBA) and am concerned about
    naming conventions in C#.

    I am accustomed to using Leszenski's convention for a variable is always
    preceding by it's data type, such as intWidth (designating an Integer
    variable)
    dblQuantity (designating a Double variable) and so forth.

    Is there an industry standard naming convention for C# ?

    Might as well start off correctly.


  • Jon Skeet [C# MVP]

    #2
    Re: New to C#

    Dan <danno492_NOSPA M@hotmail.com> wrote:[color=blue]
    > I am switching over from Visual Basic (actaully VBA) and am concerned about
    > naming conventions in C#.
    >
    > I am accustomed to using Leszenski's convention for a variable is always
    > preceding by it's data type, such as intWidth (designating an Integer
    > variable) dblQuantity (designating a Double variable) and so forth.[/color]

    That's generally not used in .NET - at least not for public members.
    It's up to you exactly how you name private members. Personally I can't
    stand that convention - and don't like prefixes for distinguishing
    member variables from local variables either, but it's a matter of
    preference.
    [color=blue]
    > Is there an industry standard naming convention for C# ?
    >
    > Might as well start off correctly.[/color]

    See http://tinyurl.com/2cun for the MS guidelines.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Mad Murdoch

      #3
      Re: New to C#

      In Addition to this ( If its not mentioned somewhere in the guildines) ,
      dont use capitalisation to differentiate identifier names as this causes
      porting problems to VB.NET


      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1cfabe 54d096fe4798c17 8@msnews.micros oft.com...[color=blue]
      > Dan <danno492_NOSPA M@hotmail.com> wrote:[color=green]
      >> I am switching over from Visual Basic (actaully VBA) and am concerned
      >> about
      >> naming conventions in C#.
      >>
      >> I am accustomed to using Leszenski's convention for a variable is always
      >> preceding by it's data type, such as intWidth (designating an Integer
      >> variable) dblQuantity (designating a Double variable) and so forth.[/color]
      >
      > That's generally not used in .NET - at least not for public members.
      > It's up to you exactly how you name private members. Personally I can't
      > stand that convention - and don't like prefixes for distinguishing
      > member variables from local variables either, but it's a matter of
      > preference.
      >[color=green]
      >> Is there an industry standard naming convention for C# ?
      >>
      >> Might as well start off correctly.[/color]
      >
      > See http://tinyurl.com/2cun for the MS guidelines.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: New to C#

        Mad Murdoch <mad@here.net > wrote:[color=blue]
        > In Addition to this ( If its not mentioned somewhere in the guildines) ,
        > dont use capitalisation to differentiate identifier names as this causes
        > porting problems to VB.NET[/color]

        Only if both of them are non-private. My preferred naming convention
        uses a private variable of name foo with a public property of name Foo.
        That doesn't cause any problems with VB.NET, as no other class can see
        the private variable.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Mad Murdoch

          #5
          Re: New to C#

          You will get a "Already Declared" error in VB.NET on the identifier name for
          the Property itself

          [color=blue]
          > Only if both of them are non-private. My preferred naming convention
          > uses a private variable of name foo with a public property of name Foo.
          > That doesn't cause any problems with VB.NET, as no other class can see
          > the private variable.
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • WRH

            #6
            Re: New to C#

            Hello

            You may want to look at Microsoft's FxCop which has among
            other things Microsoft's naming conventions. Available at


            "Dan" <danno492_NOSPA M@hotmail.com> wrote in message
            news:eOYgYYuXFH A.584@TK2MSFTNG P15.phx.gbl...[color=blue]
            > Hi All,
            > I am switching over from Visual Basic (actaully VBA) and am concerned
            > about naming conventions in C#.
            >
            > I am accustomed to using Leszenski's convention for a variable is always
            > preceding by it's data type, such as intWidth (designating an Integer
            > variable)
            > dblQuantity (designating a Double variable) and so forth.
            >
            > Is there an industry standard naming convention for C# ?
            >
            > Might as well start off correctly.
            >[/color]


            Comment

            • Mad Murdoch

              #7
              Re: New to C#

              I've tested that last year in the summer, it's quite good really but I found
              it a bit over the top. I think it would prevent me from having a decent
              throughput if I were using it in anger.



              "WRH" <no_spam@videot ron.ca> wrote in message
              news:uK%23X04wX FHA.2884@tk2msf tngp13.phx.gbl. ..[color=blue]
              > Hello
              >
              > You may want to look at Microsoft's FxCop which has among
              > other things Microsoft's naming conventions. Available at
              > http://www.gotdotnet.com/team/fxcop/
              >
              > "Dan" <danno492_NOSPA M@hotmail.com> wrote in message
              > news:eOYgYYuXFH A.584@TK2MSFTNG P15.phx.gbl...[color=green]
              >> Hi All,
              >> I am switching over from Visual Basic (actaully VBA) and am concerned
              >> about naming conventions in C#.
              >>
              >> I am accustomed to using Leszenski's convention for a variable is always
              >> preceding by it's data type, such as intWidth (designating an Integer
              >> variable)
              >> dblQuantity (designating a Double variable) and so forth.
              >>
              >> Is there an industry standard naming convention for C# ?
              >>
              >> Might as well start off correctly.
              >>[/color]
              >
              >[/color]


              Comment

              • WRH

                #8
                Re: New to C#

                I agree..however I learned about some stuff like assembly permissions etc
                that I had no idea existed..eg
                [assembly:Securi tyPermission(Se curityAction.Re questMinimum,
                UnmanagedCode=t rue)]



                "Mad Murdoch" <mad@here.net > wrote in message
                news:O3RNR7wXFH A.3620@TK2MSFTN GP09.phx.gbl...[color=blue]
                > I've tested that last year in the summer, it's quite good really but I
                > found it a bit over the top. I think it would prevent me from having a
                > decent throughput if I were using it in anger.
                >
                >
                >
                > "WRH" <no_spam@videot ron.ca> wrote in message
                > news:uK%23X04wX FHA.2884@tk2msf tngp13.phx.gbl. ..[color=green]
                >> Hello
                >>
                >> You may want to look at Microsoft's FxCop which has among
                >> other things Microsoft's naming conventions. Available at
                >> http://www.gotdotnet.com/team/fxcop/
                >>
                >> "Dan" <danno492_NOSPA M@hotmail.com> wrote in message
                >> news:eOYgYYuXFH A.584@TK2MSFTNG P15.phx.gbl...[color=darkred]
                >>> Hi All,
                >>> I am switching over from Visual Basic (actaully VBA) and am concerned
                >>> about naming conventions in C#.
                >>>
                >>> I am accustomed to using Leszenski's convention for a variable is always
                >>> preceding by it's data type, such as intWidth (designating an Integer
                >>> variable)
                >>> dblQuantity (designating a Double variable) and so forth.
                >>>
                >>> Is there an industry standard naming convention for C# ?
                >>>
                >>> Might as well start off correctly.
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • Mark Rance

                  #9
                  Re: New to C#


                  "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                  news:MPG.1cfabe 54d096fe4798c17 8@msnews.micros oft.com...[color=blue]
                  > Dan <danno492_NOSPA M@hotmail.com> wrote:[color=green]
                  >> I am switching over from Visual Basic (actaully VBA) and am concerned
                  >> about
                  >> naming conventions in C#.
                  >>
                  >> I am accustomed to using Leszenski's convention for a variable is always
                  >> preceding by it's data type, such as intWidth (designating an Integer
                  >> variable) dblQuantity (designating a Double variable) and so forth.[/color]
                  >
                  > That's generally not used in .NET - at least not for public members.
                  > It's up to you exactly how you name private members. Personally I can't
                  > stand that convention - and don't like prefixes for distinguishing
                  > member variables from local variables either, but it's a matter of
                  > preference.[/color]

                  I agree, that annoying m_ prefix for member variables. And Hungarian
                  notation...bane of all developers who want pronounce-able le names.

                  -Mark



                  Comment

                  • Jon Skeet [C# MVP]

                    #10
                    Re: New to C#

                    Mad Murdoch <mad@here.net > wrote:[color=blue]
                    > You will get a "Already Declared" error in VB.NET on the identifier name for
                    > the Property itself[/color]

                    What, when trying to use a class written in C#? I'm not suggesting
                    trying to do use that convention when writing classes in VB.NET - only
                    in C#, and then consuming the class in VB.NET.

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                    If replying to the group, please do not mail me too

                    Comment

                    • Mad Murdoch

                      #11
                      Re: New to C#

                      OK, I was talking about converting code, not just consuming it.

                      Cheers

                      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                      news:MPG.1cfb74 23424abc1398c17 b@msnews.micros oft.com...[color=blue]
                      > Mad Murdoch <mad@here.net > wrote:[color=green]
                      >> You will get a "Already Declared" error in VB.NET on the identifier name
                      >> for
                      >> the Property itself[/color]
                      >
                      > What, when trying to use a class written in C#? I'm not suggesting
                      > trying to do use that convention when writing classes in VB.NET - only
                      > in C#, and then consuming the class in VB.NET.
                      >
                      > --
                      > Jon Skeet - <skeet@pobox.co m>
                      > http://www.pobox.com/~skeet
                      > If replying to the group, please do not mail me too[/color]


                      Comment

                      • Jon Skeet [C# MVP]

                        #12
                        Re: New to C#

                        Mad Murdoch <mad@here.net > wrote:[color=blue]
                        > OK, I was talking about converting code, not just consuming it.[/color]

                        Right - that shouldn't be an issue for the OP, who is converting *from*
                        VB *to* C#.

                        --
                        Jon Skeet - <skeet@pobox.co m>
                        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                        If replying to the group, please do not mail me too

                        Comment

                        • Mad Murdoch

                          #13
                          Re: New to C#

                          Yes, Jon, I see that; but it is nevertheless something to beware of. I have
                          experience of this when converting code written by others and have had
                          headaches as a result. Do you resent me adding to your reply with what I
                          considered a useful watchpoint ?



                          "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                          news:MPG.1cfc15 7a146286298c186 @msnews.microso ft.com...[color=blue]
                          > Mad Murdoch <mad@here.net > wrote:[color=green]
                          >> OK, I was talking about converting code, not just consuming it.[/color]
                          >
                          > Right - that shouldn't be an issue for the OP, who is converting *from*
                          > VB *to* C#.
                          >
                          > --
                          > Jon Skeet - <skeet@pobox.co m>
                          > http://www.pobox.com/~skeet
                          > If replying to the group, please do not mail me too[/color]


                          Comment

                          • Jon Skeet [C# MVP]

                            #14
                            Re: New to C#

                            Mad Murdoch <mad@here.net > wrote:[color=blue]
                            > Yes, Jon, I see that; but it is nevertheless something to beware of. I have
                            > experience of this when converting code written by others and have had
                            > headaches as a result. Do you resent me adding to your reply with what I
                            > considered a useful watchpoint ?[/color]

                            Not particularly - I thought it was just worth adding that it needn't
                            be a problem, while you're in C#, even if other developers who use your
                            class use VB.NET. That wasn't clear from your post - you just said not
                            to use a fairly common convention, despite the fact that it works fine.

                            --
                            Jon Skeet - <skeet@pobox.co m>
                            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                            If replying to the group, please do not mail me too

                            Comment

                            • Steve Walker

                              #15
                              Re: New to C#

                              In message <MPG.1cfade305b cdf0e198c179@ms news.microsoft. com>, Jon Skeet
                              <?@pobox.com.in valid> writes[color=blue]
                              >Mad Murdoch <mad@here.net > wrote:[color=green]
                              >> In Addition to this ( If its not mentioned somewhere in the guildines) ,
                              >> dont use capitalisation to differentiate identifier names as this causes
                              >> porting problems to VB.NET[/color]
                              >
                              >Only if both of them are non-private. My preferred naming convention
                              >uses a private variable of name foo with a public property of name Foo.
                              >That doesn't cause any problems with VB.NET, as no other class can see
                              >the private variable.[/color]

                              Mine too, though I've come across people who hate it.

                              --
                              Steve Walker

                              Comment

                              Working...