Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Automatic Properties

Automatic Properties

Scheduled Pinned Locked Moved C#
question
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GChannon
    wrote on last edited by
    #1

    Hi, If you use an automatic property and want to reference it within the same class I assume you would specify the property but if you had another property within the same class that required validation you would reference the field. Don't you think this is messy code? <code> private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get; set; } public void Foo() { string test = _firstName + LastName; } </code>

    C R 2 Replies Last reply
    0
    • G GChannon

      Hi, If you use an automatic property and want to reference it within the same class I assume you would specify the property but if you had another property within the same class that required validation you would reference the field. Don't you think this is messy code? <code> private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get; set; } public void Foo() { string test = _firstName + LastName; } </code>

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I think automatic properties are ugly to start with.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • G GChannon

        Hi, If you use an automatic property and want to reference it within the same class I assume you would specify the property but if you had another property within the same class that required validation you would reference the field. Don't you think this is messy code? <code> private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get; set; } public void Foo() { string test = _firstName + LastName; } </code>

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        Why not like this? public void Foo() { string test = FirstName + LastName; } The fact that there is a field doesn't mean you have to use it... Robert

        G 1 Reply Last reply
        0
        • R Robert Rohde

          Why not like this? public void Foo() { string test = FirstName + LastName; } The fact that there is a field doesn't mean you have to use it... Robert

          G Offline
          G Offline
          GChannon
          wrote on last edited by
          #4

          The Microsoft Coding Guidelines says you should use fields internally within a class. I could be wrong?!?!?

          P R 2 Replies Last reply
          0
          • G GChannon

            The Microsoft Coding Guidelines says you should use fields internally within a class. I could be wrong?!?!?

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            They are guidelines. Not the law. Judge Dredd isn't going to pay a visit because of this.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            M 1 Reply Last reply
            0
            • P Pete OHanlon

              They are guidelines. Not the law. Judge Dredd isn't going to pay a visit because of this.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              M Offline
              M Offline
              MaxRelaxman
              wrote on last edited by
              #6

              He will if you name all your controls TextBox1 and ComboBox1 though. Okay, I can dream...

              P L 2 Replies Last reply
              0
              • M MaxRelaxman

                He will if you name all your controls TextBox1 and ComboBox1 though. Okay, I can dream...

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                He mightn't, but I will visit with the wet towel of vengeance ready to whip his sorry ass.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                1 Reply Last reply
                0
                • M MaxRelaxman

                  He will if you name all your controls TextBox1 and ComboBox1 though. Okay, I can dream...

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  My first job was in a very small startup. The owner thought he was a developer and created variables 'a' and 'b' then when he needed more he would go to 'aa' and 'bb' I'm still waiting to see anyone top that story, and it's true! :laugh:

                  led mike

                  1 Reply Last reply
                  0
                  • G GChannon

                    The Microsoft Coding Guidelines says you should use fields internally within a class. I could be wrong?!?!?

                    R Offline
                    R Offline
                    Robert Rohde
                    wrote on last edited by
                    #9

                    Those guidelines were probably written before automatic properties were introduced. I made just a suggestion. You said it looked ugly... :laugh: Robert

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups