Re:Apple Silicon M1: Black Magic Fuckery
by jmnicolas on Wednesday November 25, 2020 @08:12AM
(#25208844)
I just checked, apparently structs can have methods. Is it a new thing or me that was ignorant?
Re:Apple Silicon M1: Black Magic Fuckery
by reader_mode on Wednesday November 25, 2020 @08:17AM
(#25208873)
You could always have methods (for as long as I can remember at least, I started using .NET in 3.0 days), you just can't inherit structs or use virtual methods because structs don't have virtual method table. You can implement interfaces however and override operators - it's very nice for implementing 3D graphics math primitives like vectors and matrices, way better than Java in this regard which was what got me into C# way back then.
You can and should implement IEquatable on a struct, especially if you plan on placing them in a hashset - the default implementation will use reflection and will be slow but it's easy to override.