is there a difference between [Serializable] and [Serializable()] in c#?

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.

anyone an idea?

Answers


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()
{
}

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.


No, there is no difference. [Serializable] is just syntactic sugar for [Serializable()] because the C# syntax lets you miss out the constructor brackets if there is a default attribute constructor.

Note that both are really syntactic sugar for [SerializableAttribute()] as attribute declarations also let you miss the Attribute suffix.


both uses the default c'tor, there is no difference at all.


Need Your Help

How to use *.lib file in C# application?

c# .net wpf dll .lib

So I have some .lib file (generated like this one) How to use it from my C# WPF application?

OmniThreadLibrary: How to detect when all recursively scheduled (=pooled) threads have completed?

multithreading delphi recursion threadpool omnithreadlibrary

Let's say I have to recursively iterate over items stored in a tree structure in the background and I want to walk this tree using multiple threads from a thread pool (one thread per "folder" node)...