您可以应用在C#多个字段属性? [英] Can you apply a attribute to multiple fields in C#?
本文介绍了您可以应用在C#多个字段属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎并不可能,但我会问反正...是否有可能在C#中一次应用单一属性的多个领域?
This doesn't seem possible, but I'll ask anyway... Is it possible in C# to apply a single attribute to multiple fields at once?
public class MyClass {
[SomeAttribute]
public int m_nVar1;
[SomeAttribute]
public int m_nVar2;
public int m_nVar3;
}
有短手的方法来把SomeAttribute关于m_Var1&放; m_Var2,但不能在m_nVar3?目前,我们正在将属性的每个字段之前,但它会很高兴把使用块内的属性的所有字段。
Is there a short-hand method to put the "SomeAttribute" on m_Var1 & m_Var2, but not on m_nVar3? Currently, we are placing the attributes before each field, but it would be nice to put all the fields using a attribute inside a block.
推荐答案
是的,这是可能的:
[SomeAttribute]
public int m_nVar1, m_nVar2;
(但显然只有如果类型是相同的)
(but obviously only if the types are the same)
这篇关于您可以应用在C#多个字段属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文