您可以应用在C#多个字段属性?

编程入门 行业动态 更新时间:2024-10-26 04:32:28
本文介绍了您可以应用在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#多个字段属性?

本文发布于:2023-11-07 17:19:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567016.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   您可以   字段   用在   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!