C# 特性


using System.ComponentModel.DataAnnotations;

 

//特性是个类,继承自Attribute
//系统自带特性
//自定义特性


class AccountViewModel
{

[Required]
[Display(Name ="邮箱")]
[Define("这是第一个特性的创建!")]
public string Email { get; set; }
}

/// <summary>
/// 创建特性
/// </summary>
public class DefineAttribute:Attribute
{
public DefineAttribute(string showInfo)
{
Console.WriteLine(showInfo);
}
}

posted @ 2023-05-18 22:29  .net&new  阅读(16)  评论(0)    收藏  举报