Combining multiple attributes in C#

前端 未结 3 2035
旧巷少年郎
旧巷少年郎 2020-12-17 07:32

Is there a functional difference between the following syntax...

[Foo, Bar]
public class Baz {}

...and this syntax?

[Foo]
[         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 08:17

    From a readability standpoint separate attributes are preferred.

    Think about the case where you are passing some type of parameter

     [Foo(typeof(int)), Bar(typeof(decimal), MessageTemplate="Bar")]
    

    versus

     [Foo(typeof(int))]
     [Bar(typeof(decimal), MessageTemplate="Bar")]
    

    I would also argue, if you could combine them into one, they should be one tag.

提交回复
热议问题