A15_特性
来源:互联网 发布:node api 框架 编辑:程序博客网 时间:2024/06/05 19:54
/* * * Obsolete * * * * **/using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Reflection;using System.Diagnostics;namespace A15_Attribute{ class Demo1 { //[Obsolete("该方法已过时,请使用NewMethod()替换",true)] //表示必须替换 [Obsolete("该方法已过时,请使用NewMethod()替换")] public void OldMethod() { Console.WriteLine("这是旧方法"); } public void NewMethod() { Console.WriteLine("这是新方法"); } static void Main1(string[] args) { Demo1 obj = new Demo1(); obj.OldMethod(); obj.NewMethod(); } }}
/* * * 实现条件编译 * 1.使用Condition特性,针对方法 * * 2.使用预编译指令,非常灵活,直接影响所包含的所有行代码 * * **///#define OnlyTest //允许测试方法运行//#define debugusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Reflection;using System.Diagnostics;namespace A15_Attribute{ class Demo2 { [Conditional("OnlyTest")]//条件执行,默认不执行 public void TestMethod() { Console.WriteLine("这是测试方法"); } public void Method1() { Console.WriteLine("这是普通方法1"); } public void Method2() { Console.WriteLine("这是普通方法2"); } public void Test() { TestMethod(); Method1(); TestMethod(); Method2(); } //条件编译 public void Test2() { Console.WriteLine("aaa"); Console.WriteLine("bbb"); Console.WriteLine("ccc");#if debug //条件编译 如果定义了宏debug 则执行 Console.WriteLine("ddd");#else Console.WriteLine("eee");#endif } static void Main(string[] args) { Demo2 obj = new Demo2(); obj.Test(); obj.Test2(); } }}
阅读全文
0 0
- A15_特性
- 特性
- 特性
- 特性
- 特性
- 各向同性特性、各向异性特性
- WebWork2特性
- WebWork2特性
- WebWork2特性
- FreeMarker特性
- 系统特性
- 三极管特性
- ActiveSync45特性
- java特性
- oracle11g 特性
- 定制特性
- LINQ特性
- ActiveMQ特性
- 1002: 简单多项式求值
- docker实战一之Centos安装docker
- bzoj 4988: 塔 哈希
- 将图片上传到FTP服务器
- git从码云下载ibase4j代码
- A15_特性
- 汽车打不着火,老司机竟然能这样推着!
- test title
- leetcode题解-82. Remove Duplicates from Sorted List II
- 【1701H1】【穆晨】【171210】连续第六十一天总结
- 怎么登录Mysql
- CSS实战--实现侧边栏滑进滑出
- 100个好看的适合logo的英文字体推荐下载
- hdu5452(LCA+DFS)