
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to work with attributes in C#
An attribute is a declarative tag that is used to convey information to runtime about the behaviors of various elements like classes, methods, structures, enumerators, assemblies etc. in your program. You can add declarative information to a program by using an attribute. A declarative tag is depicted by square ([ ]) brackets placed above the element it is used for.
The following is the syntax of an attribute −
[attribute(positional_parameters, name_parameter = value, ...)] Element
The .Net Framework provides two types of attributes: the pre-defined attributes and custom built attributes.
Let us see how to declare a custom attribute −
//a custom attribute BugFix to be assigned to a class and its members [AttributeUsage( AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)] public class DeBugInfo : System.Attribute
- Related Articles
- How to add and remove HTML attributes with jQuery?
- How to work with Bootstrap?
- How to work with Structs in JavaScript?
- How to work with document.anchors in JavaScript?
- How to work with document.body in JavaScript?
- How to work with document.embeds in JavaScript?
- How to work with document.documentElement in JavaScript?
- How to work with document.head in JavaScript?
- How to work with document.forms in JavaScript?
- How to work with document.images in JavaScript?
- How to work with document.links in JavaScript?
- How to work with document.title in JavaScript?
- How to work with getDeclaringClass() in Java
- How to work with Picasso in Android
- How to work with Glide in Android

Advertisements