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. Property vs Attribute

Property vs Attribute

Scheduled Pinned Locked Moved C#
csharpc++visual-studioperformancequestion
4 Posts 4 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.
  • C Offline
    C Offline
    Chris Hafey
    wrote on last edited by
    #1

    In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey

    N J N 3 Replies Last reply
    0
    • C Chris Hafey

      In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Properties basically accomplish the same thing. Each propert should have an accompanying private field for the actual value. The only advantage is that you can do this :- abc.val = whatever; Nish


      The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?

      1 Reply Last reply
      0
      • C Chris Hafey

        In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey

        J Offline
        J Offline
        James T Johnson
        wrote on last edited by
        #3

        You should use properties when you are dealing with storing the data in a private variable. You should use Get/Set methods when that data is NOT being stored cannot be accessed as quickly as a "return myPrivateData;". Some applications of this type would be retreive the customer name from the database; return all the prcoesses running on the system, etc... The line is a fine one and its quite elastic so just go with what feels right :) James Simplicity Rules!

        1 Reply Last reply
        0
        • C Chris Hafey

          In C++, I would declare my data values as private members with public get/set methods. I can do the same thing in C#, but I can also use properties. Any guideance on when to use one vs the other? Is there any performance/size difference? Thanks Chris Hafey

          N Offline
          N Offline
          Neil Van Note
          wrote on last edited by
          #4

          Stick with Properties when appropriate. The Property Grid likes them, the debugger likes them, and Serialization likes them. Go with the flow, it will make your life easier... Regards

          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