当前位置:网站首页>c#高级编程-特性篇
c#高级编程-特性篇
2022-06-13 07:02:00 【万年之光】
特性
1.自定义特性类的定义
自定义特性类定义时类名后缀必须为Attribute,还需要继承于Attribute类,而且必须要指定其应用范围,如下代码所示:
[AttributeUsage(AttributeTargets.Class)]//作用于类
class sealed UIAttribute:Attribute
{
public int number;
}
2.特性如何拿到
通过反射去拿到(反射一般为类、文件的读取),如下所示:
[UI(number=100)]
class Fk{
}
void Main()//这里模仿c++的main函数写法,无需注意
{
UIAttribute[] s = (UIAttribute[])t.GetCustomAttributes(typeof(UIAttribute), false);
//FKAttribute[] s = t.GetCustomAttributes(typeof(FKAttribute), false) as FKAttribute[];
foreach(var s1 in s) {
Console.WriteLine("fk"+s1.number);
}
}
边栏推荐
- Is it safe to open an account online in Hangzhou?
- Is it safe for Hangzhou Securities to open an account?
- Jinglianwen technology provides voice data acquisition and labeling services
- IIS batch bind domain name
- Select all select none JS code implementation
- An article allows you to quickly understand the fission growth password of social e-commerce user marketing and avoid stepping on the pit
- 汇编语言基础:寄存器和寻址方式
- Try to use renderdoc to view the shader code of UE
- Tikv key performance parameters and optimization
- Can flush open a stock account? Is it safe?
猜你喜欢
![[RS-422 and RS-485] RS-422 and RS-485 serial interface standard](/img/08/e50df07d387b2f2d57a518caedc795.jpg)
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard

Host computer development (Architecture Design of firmware download software)

Computer network interview questions

Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?

As the new trend of blind box e-commerce, how can the platform use blind box play to drain at low cost?

Differences between SQL and NoSQL of mongodb series

Priority analysis of list variables in ansible playbook and how to separate and summarize list variables

Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge

如何使用望友DFM软件进行冷板分析

Test development programmers, are you still confused? You can't define yourself as a yard farmer
随机推荐
Tidb implementation plan -- III
RT thread simulator lvgl control: switch switch button control
Jinglianwen Technology: current situation and solutions of data annotation industry
Detailed Mr Atlas of hip joint (Reprinted)
JS case Xiaomi second kill countdown New Year Countdown
The new retail market has set off blind box e-commerce. Can the new blind box marketing model bring dividends to businesses?
Jinglianwen technology provides a one-stop smart home data acquisition and labeling solution
Upper computer development (code debugging of firmware download software)
Yolov5 analysis | parameters and performance indicators
汇编语言基础:寄存器和寻址方式
景联文科技提供一站式智能家居数据采集标注解决方案
Comment utiliser le logiciel wangyou DFM pour l'analyse des plaques froides
Why is the blind box e-commerce mode so popular?
16、 IO stream (II)
【腾讯阿里最全面试题集锦】(四面:3轮技术+1轮HR)
【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
景联文科技:数据标注行业现状及解决方案
The new business outlet of beautiful Tiantian second mode will be popular in the Internet e-commerce market
2022-06-12:在N*N的正方形棋盤中,有N*N個棋子,那麼每個格子正好可以擁有一個棋子。 但是現在有些棋子聚集到一個格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二維數組代錶,一
【云原生 | Kubernetes篇】Kubernetes 配置