Use Conditional Attributes instead of #if - Effective C#学习笔记(4)
来源:互联网 发布:8080端口号被占用 编辑:程序博客网 时间:2024/05/16 15:18
使用#if DEBUG / #endif这种预定义符,或许是老C++程序员的习惯了。我们仍然认为,这种预编译指令比较死板,不够灵活, 取代的方法是用运行时的C#特性(Attributes)。
C#的特性Conditional是在System.Diagnostics名称空间下的,此特性仅支持方法和属性,不支持类。
[Conditional("DEBUG")]
public void Method() {}
当你在某些地方调用以上Method时,系统会判断当前是否为DEBUG模式,如果不是,将不会执行。
- Use Conditional Attributes instead of #if - Effective C#学习笔记(4)
- Effective C# 4:use conditional attributes instead of #if
- Always use Properties instead of Accessible Data Members - Effective C#学习笔记(1)
- An effective way to use pattern to instead of multiple if else statements
- Effective C# 1:Always Use Properties Instead of Accessible Data Members
- Effective C# Item4:使用Conditional特性代替#if条件编译
- When to Use Delegates Instead of Interfaces (C# Programming Guide)
- Use Conditional attribute in C#
- if(Conditional statement)
- use supervisor instead of nohup
- 干活来袭:Effective Concurrency: Know When to Use an Active Object Instead of a Mutex
- Effective Objective-C 2.0:Item 50: Use NSCache Instead of NSDictionary for Caches
- Effective C# 学习笔记
- 《Effective C#》Item 4:使用Conditional属性来代替IF/ENDIF程序块
- 转:Effective C#》Item 4:使用Conditional属性来代替IF/ENDIF程序块
- 《Effective C#》Item 4:使用Conditional属性来代替IF/ENDIF程序块
- 提高C#编程水平的50个要点 之四“使用条件属性 (Conditional Attributes) 来代替条件编译语句 #if”
- use sys_guid() to instead of sequence
- c#时间格式
- Java-Composition for Code Reuse
- Visual Studio 2005 通过静态变量及可系列化的HASHTABLE变量优化工厂模式(Factory)的效率,提升性能(E8.Net工作流应用系统优化系列四)
- struts1和struts2的比较
- bea weblogic workflow worklist 介绍(4)
- Use Conditional Attributes instead of #if - Effective C#学习笔记(4)
- int 0x80 Definition
- 国内各大域名注册机构域名管理面板登陆地址
- 编译器原理及相关
- IIs服务没能及时响应启动或控制请求
- 20080327 至今单身有感
- 理解SetWindowOrg,SetViewportOrg,SetWindowExt,SetViewportExt (转)
- 求两个日期时间的差 以*天**小时**分钟
- 一个非常可爱的图片