0
\$\begingroup\$

What is the difference between Serializable, and System.Serializable?

I'm guessing SerializeField is only for attributes of a class. What is the difference between the above two, then?

\$\endgroup\$
1
\$\begingroup\$

Unless I'm mistaken, there is no difference - System.Serializable is just the fully qualified name of Serializable.

C# has this notions of namespaces; a namespace is a way to organize code (it's a "space for (type) names") - think of a namespace as of a box that contain stuff you might want to use. This helps organize things and avoid naming conflicts (if, say, two independently developed libraries use the same name for a class).

So, the Serializable attribute is declared/placed within the System namespace. When you say System.Serializable, you're just saying "get Serializable from System".

But if you have a using System; statement at the top, you can omit the namespace and just write Serializable; the compiler can then infer that it means System.Serializable, saving you a few keystrokes.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.