Can you apply a attribute to multiple fields in C#?

会有一股神秘感。 提交于 2019-12-01 16:12:42

Yes, it's possible:

[SomeAttribute]
public int m_nVar1, m_nVar2;

(but obviously only if the types are the same)

This could work?, but might end up being pretty tedious

public class CustomClass
{
 [CustomAttribute]
 public dynamic value { get; set; }
}

public class MyClass
{
    public CustomClass m_nVar1, var2, var3;
    public MyClass()
    {
        m_nVar1.value = (int)m_nVar1.value;
        var2.value = (string)var2.value;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!