471,594 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Design issue: Struct vs. Class

After reading the thread "Struct faster than class?" I thought I should surely understand if I am doing anything wrong in my work.

First, Jon you are very professional. Excellent. I will wish you as my mentor.

Anyways, getting to my question --

I am in need of enums a lot in my project. More for meta data reasons. e.g. Toggle -on/off, Close/Open etc.
Most are int type values but this one meta data is full of Guid. Now that enum supports int etc and not string or Guid so I endup making it a Struct. No perticular reason, just to make it look different while programming (as there are tons of classes to keep track of). Anyways, I am not sure if this approch is better (or even ok). Not being familier with memory management etc (and will love to get pointers to read more on this also) I am not sure how things are handled run time if it is changed to static Class type. I have so many questions on this topic alone so please feel free to throw anything on this side.

Thanks,
Po
Dec 24 '05 #1
2 1110
Pohihihi,

In this case, it is better to use a class. In actuality, it doesn't
really matter, because you will be accessing static
fields/methods/properties on the type, which doesn't have anything to do
with whether or not it is a reference type or a structure.

The reason it is better to use a class is that in C# 2.0, you can create
a static class, which will help enforce your design in this situation.
Since you are trying to duplicate enumerations, you will have to create
static read-only fields on your type, and the static keyword will help you
make sure you do that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pohihihi" <no*****@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
After reading the thread "Struct faster than class?" I thought I should
surely understand if I am doing anything wrong in my work.

First, Jon you are very professional. Excellent. I will wish you as my
mentor.

Anyways, getting to my question --

I am in need of enums a lot in my project. More for meta data reasons. e.g.
Toggle -on/off, Close/Open etc.
Most are int type values but this one meta data is full of Guid. Now that
enum supports int etc and not string or Guid so I endup making it a Struct.
No perticular reason, just to make it look different while programming (as
there are tons of classes to keep track of). Anyways, I am not sure if this
approch is better (or even ok). Not being familier with memory management
etc (and will love to get pointers to read more on this also) I am not sure
how things are handled run time if it is changed to static Class type. I
have so many questions on this topic alone so please feel free to throw
anything on this side.

Thanks,
Po
Dec 26 '05 #2
Thank you Nicholas, that helps.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:um**************@TK2MSFTNGP12.phx.gbl...
Pohihihi,

In this case, it is better to use a class. In actuality, it doesn't
really matter, because you will be accessing static
fields/methods/properties on the type, which doesn't have anything to do
with whether or not it is a reference type or a structure.

The reason it is better to use a class is that in C# 2.0, you can
create a static class, which will help enforce your design in this
situation. Since you are trying to duplicate enumerations, you will have
to create static read-only fields on your type, and the static keyword
will help you make sure you do that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pohihihi" <no*****@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
After reading the thread "Struct faster than class?" I thought I should
surely understand if I am doing anything wrong in my work.

First, Jon you are very professional. Excellent. I will wish you as my
mentor.

Anyways, getting to my question --

I am in need of enums a lot in my project. More for meta data reasons.
e.g. Toggle -on/off, Close/Open etc.
Most are int type values but this one meta data is full of Guid. Now that
enum supports int etc and not string or Guid so I endup making it a
Struct. No perticular reason, just to make it look different while
programming (as there are tons of classes to keep track of). Anyways, I am
not sure if this approch is better (or even ok). Not being familier with
memory management etc (and will love to get pointers to read more on this
also) I am not sure how things are handled run time if it is changed to
static Class type. I have so many questions on this topic alone so please
feel free to throw anything on this side.

Thanks,
Po

Dec 26 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Ash | last post: by
11 posts views Thread by | last post: by
5 posts views Thread by Michael Olea | last post: by
reply views Thread by ma740988 | last post: by
5 posts views Thread by aaragon | last post: by
8 posts views Thread by obrianpatrick | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.