我已经碰到了使用任何两个符号的例子。我找不到它的任何事情告诉哪一个是常见的一种,为什么2符号是允许的,如果有实际两者之间的细微差别。
I've bumped into examples using either of both notations. I can't find anything about it what tells which one is the common one, why 2 notations are allowed, and if there is actually any subtle difference between the two.
任何人的想法?
推荐答案不,没有任何功能上的差异。
Nope, no functional difference.
为什么两种不同的风格,你问?所述第一符号是允许为了简便起见。第二符号是允许的,因为某些属性取参数:
Why the 2 different styles, you ask? The first notation is allowed for brevity. The 2nd notation is allowed because some attributes take parameters:
[Category("Foobar related methods.")] public void Foo() { }
另外请注意,[Serializable接口]实际上只是短期的手[SerializableAttribute()] - C#,您可以省略属性后缀以及空构造括号
Also note that [Serializable] is really just short-hand for [SerializableAttribute()] - C# lets you omit the Attribute suffix as well as the empty constructor parens.
更多推荐
有[可序列化]和[序列化()在C#中有区别吗?
发布评论