the use of interface is prohibited with struct

  • Thread starter Thread starter puzzlecracker
  • Start date Start date
P

puzzlecracker

I am have pretty light types whose object I would like to use for
serialization thus ensure they obey the contract. Apparently, I cannot
use structs and have no choice, but to you use class.

thoughts?
 
puzzlecracker said:
I am have pretty light types whose object I would like to use for
serialization thus ensure they obey the contract. Apparently, I cannot
use structs and have no choice, but to you use class.

Use classes.

I would be very surprised if you could measure a performance difference
in the real app.

Arne
 
Can you elaborate? Your question seems to be asking why you can't write a
struct that implements a particular interface. But you can, so it seems
you must be asking some other question that's not immediately apparent.

Can you post some code that doesn't work, but which you'd like it to?

Pete

Hmm, I will try it tomorrow at work, and if it's true, I will do a lot
of changes, as I am accustomed to using a struct whenever I
declare member variables public.
 
You should never declare member variables public.  Make them properties..

Every rule has its exceptions, including this one.  But it's a good rule  
to live by.

Beyond, the question of whether a member field is public or not isn't IMHO  
a good metric for deciding whether a type should be a struct or a class.  
Doing it that way would be kind of like voting for a politician based  
solely on their gender or race.

Pete

Well, what do you suggest to use when I have a types with very few
members whose sole purpose to set/get and serialize (ReadObject,
WriteObject)? This is sort of a design question

Thanks
 
Well, what do you suggest to use when I have a types with very few
members whose sole purpose to set/get and serialize (ReadObject,
WriteObject)? This is sort of a design question

Public properties, private variables. That way you retain control.

Jon
 

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

Back
Top