Equals for structs [Answered]
Is it standard to implement GetHashCode and == and Equals for structs even if all fields should be used? because the default one is using reflection to get fields
4 Replies
it depends a bit. this article goes in depth about using it: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type
but for just value holders you don't compare it is not that needed, if it is used for comparisons, then it makes sense to create an override that does it properly.
How to define value equality for a class or struct - C# Programming...
Learn how to define value equality for a class or struct. See code examples and view available resources.
Consider just using a record struct and get the relevant implementation for free
I cannot use it because it has been added in C#8.0
My env: Unity and it does not support record
✅ This post has been marked as answered!