
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What are conditional attributes in C#?
Attributes are used for adding metadata, such as compiler instruction and other information such as comments, description, methods, and classes to a program.
This predefined attribute marks a conditional method whose execution depends on a specified preprocessing identifier.
It causes conditional compilation of method calls, depending on the specified value such as Debug or Trace. For example, it displays the values of the variables while debugging a code.
The following is the syntax of conditional attributes −
[Conditional( conditionalSymbol )]
Let us see how to work with Conditional attributes −
Example
#define DEBUG using System; using System.Diagnostics; public class Myclass { [Conditional("DEBUG")] public static void Message(string msg) { Console.WriteLine(msg); } } class Test { static void function1() { Myclass.Message("In Function 1"); function2(); } static void function2() { Myclass.Message("In Function 2"); } public static void Main() { Myclass.Message("In Main function"); function1(); Console.ReadKey(); } }
Output
In Main function In Function 1 In Function 2
- Related Questions & Answers
- What are obsolete attributes in C#?
- What are predefined attributes in C#?
- What are the attributes in C#?
- What are Conditional Operators in JavaScript?
- What are Python function attributes?
- What are event attributes in jQuery?
- What are the DataTransfer object attributes?
- What are built-in class attributes in Python?
- What are the different types of conditional statements supported by C#?
- What is conditional compilation in C language?
- attributes in C++
- What are the methods in jQuery to manipulate attributes?
- What are various attributes Of page directive in JSP?
- What is Conditional Branching?
- What are the attributes of a file object in Python?
Advertisements