Re: Struct vs Class
- From: "Bruce Wood" <brucewood@xxxxxxxxxx>
- Date: 28 Oct 2006 17:13:09 -0700
JohnGoogle@xxxxxxxxxxxxx wrote:
Thanks Dave,
I do override Equals and GetHashcode already. I guess I'll change it
back to a class. Thank you for you feedback. From what I had read, I
thought this was the case.
As a newbie, I'm interested in how much boxing / unboxing will be going
on when I define a struct as opposed to a class. I've just got Jeffrey
Richter's CLR via C# which seems to show me how to determine this via
the IL Disassembler. Some investigations to be done!
I, too, created a Fraction class for use in our company. Trust me:
don't make it a class. Simply assign meaning to "everything zero". It's
"essential" that the denominator be greater than zero only if you say
it's essential; you're writing the code, so you can make any
assumptions you want.
Simply write the internals so that denominator and numerator both zero
means "zero". Yes, it means more checks inside your code, but as I
said, trust me: making this a class will make it much less useful and
make it act much less intuitively. It should be a struct.
.
- Follow-Ups:
- Re: Struct vs Class
- From: Martin Z
- Re: Struct vs Class
- References:
- Struct vs Class
- From: JohnGoogle
- Re: Struct vs Class
- From: Dave Sexton
- Re: Struct vs Class
- From: JohnGoogle
- Struct vs Class
- Prev by Date: Re: Raising events
- Next by Date: "CS1513: } expected" ASP.NET compilation error while accessing base members
- Previous by thread: Re: Struct vs Class
- Next by thread: Re: Struct vs Class
- Index(es):
Relevant Pages
|
Loading