c# .net 特性Attribute

本文介绍了C#中特性Attribute的概念,包括什么是特性、如何直接或间接继承自Attribute,以及如何通过AttributeUsage限制特性使用场景。通过示例展示了特性在类、方法等对象上的使用,并通过反射进行实战演示,强调特性本身无行为,需要通过InvokeCenter等第三方类来激活其功能。最后,文章预告了高级篇的内容。
摘要由CSDN通过智能技术生成

准备

第一步,新建一个“控制台”,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atttibute
{
    class Program
    {
        static void Main(string[] args)
        {
            Student student = new Student();
        }
    }
}

第二步,准备一个“Student”类,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atttibute
{
    /// <summary>
    /// 这里是注释,除了让人看懂这里写的是什么,
    /// 对运行没有任何影响
    /// </summary>
   
   [Obsolete("请不要使用这个了,请使用什么来代替", true)]
    [Serializable]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

橙-极纪元JJY.Cheng

客官,1分钱也是爱,给个赏钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值