0

hi

I am trying to learn some basics about attributes in c#. As per i have refered, an attributes is just an additional information that is added to the programming elements.

I just want to know, what is the difference between attributes and properties.

Why we are moving to attributes. Before attributes what is used.

this is basics and silly question but i need to get a clear picture about this.

Please let me know ASAP

2
Contributors
1
Reply
16
Views
4 Years
Discussion Span
Last Post by Momerath
1

From Eric Lippert's blog:

Think about a typical usage of attributes:

[Obsolete]
[Serializable]
public class Giraffe : Animal
{ ...

Attributes typically do not have anything to do with the semantics of the thing being modeled. Attributes are facts about the mechanisms - the classes and fields and formal parameters and whatnot. Clearly this does not mean "a giraffe has an obsolete and a serializable." This also does not mean that giraffes are obsolete or serializable. That doesn't make any sense. This says that the class named Giraffe is obsolete and the class named Giraffe is serializable.

In short: use attributes to describe your mechanisms, use properties to model the domain.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.