Lệnh tiền xử lý #define xác định một chuỗi các ký tự, được gọi là ký hiệu. Nó tạo ra các hằng số tượng trưng.
#define cho phép bạn xác định một ký hiệu sao cho bằng cách sử dụng ký hiệu làm biểu thức được truyền cho chỉ thị #if, biểu thức sẽ đánh giá thành true.
Đây là một ví dụ -
Ví dụ
#define ONE
#undef TWO
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
#if (ONE && TWO)
Console.WriteLine("Both are defined");
#elif (ONE && !TWO)
Console.WriteLine("ONE is defined and TWO is undefined");
#elif (!ONE && TWO)
Console.WriteLine("ONE is defined and TWO is undefined");
#else
Console.WriteLine("Both are undefined");
#endif
}
}
}