() in attribute declaration

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?
 
H

Henning Krause [MVP - Exchange]

Hi,

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

Kind regards,
Henning Krause
 
S

Steven Cheng

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?
 
W

wdudek

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top