Re: Design issue: Struct vs. Class



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]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Pohihihi" <noemail@xxxxxxxxxxx> wrote in message
news:%23xHIs%23NCGHA.2908@xxxxxxxxxxxxxxxxxxxxxxx
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


.



Relevant Pages

  • Re: Design issue: Struct vs. Class
    ... > After reading the thread "Struct faster than class?" ... > Most are int type values but this one meta data is full of Guid. ... No perticular reason, just to make it look different while ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH][RFC 23/23]: Support for zero-copy TCP transmit of user space data
    ... struct page. ... There is a huge no-no in networking land on increasing skb. ... Reason is simple every skb will carry potentially unneded data as long ... not allowed to be slab ones (xfs was the last one who provided slab ...
    (Linux-Kernel)
  • Re: Carbon, threads, and windows...
    ... Actually, CImgDisplay is declared as a struct (yes, I know that almost ... definitions, one of which is chosen, depending on preprocessor flags. ... to what I read- Cocoa can only be used by Objective-C applications. ... Cocoa applications run an Objective-C method, but there is no reason why ...
    (comp.sys.mac.programmer.help)
  • Re: re[2]: Com object questions
    ... I took a look at the code that generates the Record info, ... records that don't have a guid ... Looks like it should be possible to create a python record object from ... and when I try to use a struct for the IP address using the following code: ...
    (comp.lang.python)
  • Re: Please confirm my c to c# structs
    ... Hi Mattias, ... public struct iaxc_event ... public int next_event_pointer; ... public int type; ...
    (microsoft.public.dotnet.framework.interop)

Quantcast