Overriding Equals method in Structs
Posted
by devoured elysium
on Stack Overflow
See other posts from Stack Overflow
or by devoured elysium
Published on 2010-03-30T03:24:51Z
Indexed on
2010/03/30
3:33 UTC
Read the original article
Hit count: 851
I've looked for overriding guidelines for structs, but all I can find is for classes.
At first I thought I wouldn't have to check to see if the passed object was null, as structs are value types and can't be null. But now that I come to think of it, as equals signature is
public bool Equals(object obj)
it seems there is nothing preventing the user of my struct to be trying to compare it with an arbitrary reference type.
My second point concerns the casting I (think I) have to make before I compare my private fields in my struct. How am I supposed to cast the object to my struct's type? C#'s as
keyword seems only suitable for reference types.
Thanks
© Stack Overflow or respective owner