Difference between implementing an interface and applying an attribute in C#
Posted
by RemotecUk
on Stack Overflow
See other posts from Stack Overflow
or by RemotecUk
Published on 2010-04-19T13:57:40Z
Indexed on
2010/04/19
14:13 UTC
Read the original article
Hit count: 514
This might be a stupid question but Ill ask anyway,
I was reading "OOP Demystified: A Self-Teaching Guide by Jim Keogh and Mario Giannini" chapter 11 which covers interfaces. The examples in this book are C++.
I noticed that C++ uses ISerializable to make a class serializable which you would implement where as in C# you just attribute the class with the [Serializable] attribute.
What is the key difference here? Is it that with an interface you must provide the implementation where as if you attribute something the compiler will work out the implementation for you?
I guess that with the [Serializable] attribute the .Net framework uses reflection to make the serialized object from the actual object.
That said is it possible in that case to have an [Disposable] attribute or using my theory above the framework wont know how to actually dispose of an object hence you have to do it yourself?
Would be grateful for a clarification.
Thanks.
© Stack Overflow or respective owner