Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 757
Brant Bobby Avatar asked Mar 30 '10 16:03

Brant Bobby


People also ask

Is it possible to combine attributes in Java?

It depends to the framework which is using the attribute. Combining attributes can be meaningful in order to the context which uses and interprets attributes. For example for those contexts which use .Net Type Description mechanisms you can customize the type description which .Net returns to consumers.

What is the use of attribute in C?

Attributes are used in C# to convey declarative information or metadata about various code elements such as methods, assemblies, properties, types, etc. Attributes are added to the code by using a declarative tag that is placed using square brackets ( [ ]) on top of the required code element.

Is it possible to use multiple __attribute__ in a macro?

This said, you can probably define a macro that contains the necessary attributes (according to other conditions, including values of other macros), and use the macro in the source code. Show activity on this post. You can use multiple __attribute__ specifiers separated by spaces. np.

Can you have multiple __attribute__ specifiers separated by spaces?

You can use multiple __attribute__ specifiers separated by spaces. np. Grayson has the throrougher answer here. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers.


1 Answers

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 {}  
like image 151
LBushkin Avatar answered Sep 19 '22 23:09

LBushkin