From 5c0fe2a3a16af6909c361b12cb5dab2d262dd71a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 19:36:54 +0000 Subject: [PATCH 1/2] Initial plan From b916f37e1b888ab1ae9dc604099e3d26642c0927 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 19:43:34 +0000 Subject: [PATCH 2/2] Fix misleading equality testing method documentation Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/csharp/fundamentals/object-oriented/objects.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/csharp/fundamentals/object-oriented/objects.md b/docs/csharp/fundamentals/object-oriented/objects.md index 9b2dd20b85d8f..9f003e0893984 100644 --- a/docs/csharp/fundamentals/object-oriented/objects.md +++ b/docs/csharp/fundamentals/object-oriented/objects.md @@ -34,12 +34,12 @@ The memory for both `p1` and `p2` is allocated on the thread stack. That memory When you compare two objects for equality, you must first distinguish whether you want to know whether the two variables represent the same object in memory, or whether the values of one or more of their fields are equivalent. If you're intending to compare values, you must consider whether the objects are instances of value types (structs) or reference types (classes, delegates, arrays). -- To determine whether two class instances refer to the same location in memory (which means that they have the same *identity*), use the static method. ( is the implicit base class for all value types and reference types, including user-defined structs and classes.) -- To determine whether the instance fields in two struct instances have the same values, use the method. Because all structs implicitly inherit from , you call the method directly on your object as shown in the following example: +- To determine whether two class instances refer to the same location in memory (which means that they have the same *identity*), use the static method. ( is the implicit base class for all value types and reference types, including user-defined structs and classes.) +- The method, by default, determines whether the instance fields in two struct instances have the same values. Because all structs implicitly inherit from , you call the method directly on your object as shown in the following example: :::code language="csharp" source="./snippets/objects/Equality.cs" ID="Snippet32"::: - The implementation of `Equals` uses boxing and reflection in some cases. For information about how to provide an efficient equality algorithm that is specific to your type, see [How to define value equality for a type](../../programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type.md). Records are reference types that use value semantics for equality. + The default implementation of `Equals` uses boxing and reflection in some cases. For information about how to provide an efficient equality algorithm that is specific to your type, see [How to define value equality for a type](../../programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type.md). Records are reference types that use value semantics for equality. - To determine whether the values of the fields in two class instances are equal, you might be able to use the method or the [== operator](../../language-reference/operators/equality-operators.md#equality-operator-). However, only use them if the class has overridden or overloaded them to provide a custom definition of what "equality" means for objects of that type. The class might also implement the interface or the interface. Both interfaces provide methods that can be used to test value equality. When designing your own classes that override `Equals`, make sure to follow the guidelines stated in [How to define value equality for a type](../../programming-guide/statements-expressions-operators/how-to-define-value-equality-for-a-type.md) and .