特性:给类或者方法添加一些标签信息。比如我们在调试代码程序的时候为类和方法注明调试事件,调试人以及调试时间等信息。
1.根据定义方式的不同,特性分为系统提供的特性以及自定义的特性。
系统提供的特性:
(1)Conditional:编译时,按照给出的条件决定方法是否执行。 debug 时打印调试信息,release 时取消打印。(Debug,开发测试的一种模式;Release,发布程序编译的一种模式)
#define Hello//预处理指令,加上后,才表示要执行hello方法
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtrributeTest
{
internal class Program
{
static void Main(string[] args)
{
fun1("fun1---");
Console.ReadKey();
}
static void fun1(string info)
{
Console.WriteLine(info);
MyAtrribute.function1("debug---");
MyAtrribute.hello("hello----");
}
}
public cla