tailieunhanh - Effective C#50 Specific Ways to Improve Your C# Second Edition phần 2

Câu trả lời sẽ khác nhau, nhưng phải có tất cả bốn yếu tố. 1. Luận văn: Bất chấp những hiểm nguy, Internet vẫn là một phương tiện hoàn toàn miễn phí và không bị kiểm duyệt. 2. Hỗ trợ: • Kiểm duyệt sẽ vi phạm | 22 I Chapter 1 C Language Idioms Exiting Checkstate for Person endif Using the if and endif pragmas you ve created an empty method in your release builds. The CheckState method gets called in all builds release and debug. It doesn t do anything in the release builds but you pay for the method call. You also pay a small cost to load and JIT the empty routine. This practice works fine but can lead to subtle bugs that appear only in release builds. The following common mistake shows what can happen when you use pragmas for conditional compilation public void Func string msg null if DEBUG msg GetDiagnostics endif msg Everything works fine in your debug build but your release builds happily print a blank message. That s not your intent. You goofed but the compiler couldn t help you. You have code that is fundamental to your logic inside a conditional block. Sprinkling your source code with if endif blocks makes it hard to diagnose the differences in behavior with the different builds. C has a better alternative the Conditional attribute. Using the Conditional attribute you can isolate functions that should be part of your classes only when a particular environment variable is defined or set to a certain value. The most common use of this feature is to instrument your code with debugging statements. The .NET Framework library already has the basic functionality you need for this use. This example shows how to use the debugging capabilities in the .NET Framework Library to show you how conditional attributes work and when to add them to your code. When you build the Person object you add a method to verify the object invariants From the Library of Wow eBook Item 4 Use Conditional Attributes Instead of if I 23 private void CheckState Grab the name of the calling routine string methodName new StackTrace .GetFrame 1 .GetMethod .Name Entering CheckState for Person tcalled by methodName

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.