What is Attribute Programming? What are attributes? Where are they used?

 Posted by Rohitshah on 10/7/2008 | Category: C# Interview questions | Views: 15139
Answer:

Attributes are a mechanism for adding metadata, such as compiler instructions and other data about your data, methods, and classes, to the program itself. Attributes are inserted into the metadata and are visible through ILDasm and other metadata-reading tools. Attributes can be used to identify or use the data at runtime execution using .NET Reflection.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Nandakumarpb on: 8/21/2010 | Points: 10
Iam trying add more here to complete.

Some attributes are : DllImport,WebMethod..etc.

This can be used in any of your entity(class) to give explanation of the information your want to give.
eg:[DllImport("user32.dll", EntryPoint = "MessageBox", CharSet = Unicode)]
This will tell the compiler to declare the function (which is in user32dll). DllImport attribute usually using for calling windows API].
You can also create custom attribute. refer below link for more ..
http://msdn.microsoft.com/en-us/library/sw480ze8(v=VS.71).aspx

Login to post response