Re: Struct vs Class




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.

.



Relevant Pages

  • Re: Struct vs Class
    ... Bruce, My understanding is that, if designed to be entirely immutable ... between a class and a struct. ... Simply assign meaning to "everything zero". ... Simply write the internals so that denominator and numerator both zero ...
    (microsoft.public.dotnet.languages.csharp)
  • [RFC][PATCH] ZERO PAGE again
    ... Very long time since 2.6.24 but there are still questions to ZERO PAGE ... vm_normal_page(vma, address, pte, zeropage) ... +static struct page * ...
    (Linux-Kernel)
  • [patch 1/4] Kprobes support for IA64
    ... This patch adds the kdebug die notification mechanism needed by Kprobes. ... for switch case zero. ... +struct notifier_block *ia64die_chain; ... * GNU General Public License for more details. ...
    (Linux-Kernel)
  • Re: Divide by 0 - any way to avoid?
    ... Your troubles with zeros in the denominator of the above expression are ... due entirely to Symbolic Math's inability to sufficiently simplify the ... When your denominators become zero, ... the two first partial derivatives are both zero, ...
    (comp.soft-sys.matlab)
  • Re: Comparing structs...
    ... How could it ensure that all padding is always zero? ... insist that all struct padding bits are set to zero when a struct is ... and pointer members on an implementation where pointer ...
    (comp.lang.c)

Loading