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. .NET (Core and Framework)
  4. Attribute in .net

Attribute in .net

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharptutorialquestion
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.
  • U Offline
    U Offline
    User 10763365
    wrote on last edited by
    #1

    Why we need Attribute in .net application ? Please give any real time example. Thanks in Advance

    P A 2 Replies Last reply
    0
    • U User 10763365

      Why we need Attribute in .net application ? Please give any real time example. Thanks in Advance

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

      Attributes allow us to decorate something, e.g. a class, with something that indicates to a piece of calling code that this particular thing has certain behaviour. While the operation can appear magical at times, e.g. how does marking a class as Serializable mean it can be serialized, there is always a piece of code at the other side that is checking to see if the attribute exists and acting on it if it's present. Serialization is a great example of the practical use of attributes. As well as marking a class as being capable of serialization, we can use additional attributes to say that certain types in that class should not be serialized. Then, when you attempt to serialize the class in your code, the underlying serialization engine determines that the class can be serialized but it has to ignore certain members in it.

      L 1 Reply Last reply
      0
      • U User 10763365

        Why we need Attribute in .net application ? Please give any real time example. Thanks in Advance

        A Offline
        A Offline
        AmitGajjar
        wrote on last edited by
        #3

        What else you suggest ? Whats problem with Attribute ?

        1 Reply Last reply
        0
        • P Pete OHanlon

          Attributes allow us to decorate something, e.g. a class, with something that indicates to a piece of calling code that this particular thing has certain behaviour. While the operation can appear magical at times, e.g. how does marking a class as Serializable mean it can be serialized, there is always a piece of code at the other side that is checking to see if the attribute exists and acting on it if it's present. Serialization is a great example of the practical use of attributes. As well as marking a class as being capable of serialization, we can use additional attributes to say that certain types in that class should not be serialized. Then, when you attempt to serialize the class in your code, the underlying serialization engine determines that the class can be serialized but it has to ignore certain members in it.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Clearly explained.

          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