Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

c# - Can you omit the parenthesis from attributes with no params?

I noticed when I have [Serializable] instead of [Serializable()], the code still compiles.

Is there a rule for this that you can omit the parentheses? Is it a good practice? It seems more readable to me unless I am missing something.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's no particular rule regarding best practices that I've seen anywehere on the subect.

Generally, I find that people who hand-type their attributes omit the empty parens, but code generation almost always explicitly includes them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...