() in attribute declaration

  • Thread starter Thread starter wdudek
  • Start date Start date
W

wdudek

I have seen attributes, specifically Serializable declared in 2 ways and was
wondering if anyone had any insight on the differance if there is any. These
2 ways are [Serializable] and [Serializable()]. Does the addition of the
parenthesis do anything? Is this calling a constructor? Both seem to have the
same effect in the end, but it seems like they should do something differnt?
 
Hi,

it's the same. You can just omit the parentheses if you aren't specifying
any parameters.

Kind regards,
Henning Krause
 
Hi wdudek,

both syntax is correct and there is no difference between them. You can
think them as the two declaration that one is use the default constructor
implicitly while another call the constructor explicitly(parameterless
constructor).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?d2R1ZGVr?= <[email protected]>
Subject: () in attribute declaration
Date: Wed, 12 Mar 2008 09:05:01 -0700
I have seen attributes, specifically Serializable declared in 2 ways and was
wondering if anyone had any insight on the differance if there is any. These
2 ways are [Serializable] and [Serializable()]. Does the addition of the
parenthesis do anything? Is this calling a constructor? Both seem to have the
same effect in the end, but it seems like they should do something differnt?
 
Thanks everyone, I kind of figured as much, but it's good to know for sure.

"Steven Cheng" said:
Hi wdudek,

both syntax is correct and there is no difference between them. You can
think them as the two declaration that one is use the default constructor
implicitly while another call the constructor explicitly(parameterless
constructor).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?d2R1ZGVr?= <[email protected]>
Subject: () in attribute declaration
Date: Wed, 12 Mar 2008 09:05:01 -0700
I have seen attributes, specifically Serializable declared in 2 ways and was
wondering if anyone had any insight on the differance if there is any. These
2 ways are [Serializable] and [Serializable()]. Does the addition of the
parenthesis do anything? Is this calling a constructor? Both seem to have the
same effect in the end, but it seems like they should do something differnt?
 
Back
Top