Skip to content

Commit

Permalink
Update how-to-define-value-equality-for-a-type.md (#1349)
Browse files Browse the repository at this point in the history
public and non-public fields is the same thing as fields

e.g.,  x || !x == true
  • Loading branch information
rcseacord authored and BillWagner committed Dec 21, 2016
1 parent c38c23d commit ac32b49
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ When you define a class or struct, you decide whether it makes sense to create a

5. x.`Equals`(null) returns `false`. However, null.Equals(null) throws an exception; it does not obey rule number two above.

Any struct that you define already has a default implementation of value equality that it inherits from the <xref:System.ValueType?displayProperty=fullName> override of the <xref:System.Object.Equals%28System.Object%29?displayProperty=fullName> method. This implementation uses reflection to examine all the public and non-public fields and properties in the type. Although this implementation produces correct results, it is relatively slow compared to a custom implementation that you write specifically for the type.
Any struct that you define already has a default implementation of value equality that it inherits from the <xref:System.ValueType?displayProperty=fullName> override of the <xref:System.Object.Equals%28System.Object%29?displayProperty=fullName> method. This implementation uses reflection to examine all the fields and properties in the type. Although this implementation produces correct results, it is relatively slow compared to a custom implementation that you write specifically for the type.

The implementation details for value equality are different for classes and structs. However, both classes and structs require the same basic steps for implementing equality:

Expand Down

0 comments on commit ac32b49

Please sign in to comment.