Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Cách sử dụng chỉ thị #undef trong C#?

Chỉ thị #undef cho phép bạn hủy định nghĩa một ký hiệu. Cú pháp sau:

#undef SYMBOL

Ví dụ:

#undef One

Nó đánh giá thành false khi dùng cùng với chỉ thị #if. Hãy xem 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 
        } 
    } 
}

Kết quả

Both are undefined