Atrribute purpose

  • Thread starter Thread starter archana
  • Start date Start date
A

archana

Hi
can any one please tell me what is use of attribute, exactly where
attribute will be useful for me.
 
can any one please tell me what is use of attribute, exactly where
attribute will be useful for me.

If you put an attribute Foobar on a class or class member then code
accessing your code via reflection can use the information from the
attribute to change what it will do with your code.

Arne
 
If you put an attribute Foobar on a class or class member then code
accessing your code via reflection can use the information from the
attribute to change what it will do with your code.

Example:

using System;
using System.Xml.Serialization;

namespace E
{
public class UglyName
{
}
[XmlRoot(ElementName="this-is-a-nice-name")]
public class AnotherUglyName
{
}
public class Program
{
public static void Main(string[] args)
{
(new XmlSerializer(typeof(UglyName))).Serialize(Console.Out, new
UglyName());
Console.WriteLine();
(new XmlSerializer(typeof(AnotherUglyName))).Serialize(Console.Out,
new AnotherUglyName());
Console.ReadKey();
}
}
}

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top