Search code examples
c#syntaxcoding-styleattributes

Combining multiple attributes in C#


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

[Foo, Bar]
public class Baz {}

...and this syntax?

[Foo]
[Bar]
public class Baz {}

Assuming each produces identical results when compiled, which is the preferred form?


Solution

  • There is no functional difference. It's a question of convenience and style.

    Most often, I tend to see attributes on their own lines as a way to keep them separate and easy to read. It's also nice to be able to use the line comment // to remove attributes individually.

    [A]
    [B]
    //[C] disabled
    public class Foo {}