Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Accessing Attributes and Methods 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.
To set an attribute −
[attribute(positional_parameters, name_parameter = value, ...)] Element
Here, the name of the attribute and values come inside [ ] positional parameters allow you to specify information.
Example
The following is an example to access attribute and methods in C# −
#define DEBUG
using System;
using System.Diagnostics;
public class Demo {
[Conditional("DEBUG")]
public static void Message(string str) {
Console.WriteLine(str);
}
}
class Test {
static void functionDisplay() {
Demo.Message("Our function...");
}
public static void Main() {
Demo.Message("This is Main function!");
functionDisplay();
Console.ReadKey();
}
}
Output
This is Main function! Our function...
Advertisements