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?
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.
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.
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.
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.
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 {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With