From 434c5ea916e41bd2c818857fc95575e9c45ce9f0 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Thu, 23 Nov 2023 23:30:52 +0100 Subject: [PATCH 1/3] Add note to anonymous types equality regarding separate assemblies --- docs/csharp/fundamentals/types/anonymous-types.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/csharp/fundamentals/types/anonymous-types.md b/docs/csharp/fundamentals/types/anonymous-types.md index c459b167ed122..0f0e3c0cc2402 100644 --- a/docs/csharp/fundamentals/types/anonymous-types.md +++ b/docs/csharp/fundamentals/types/anonymous-types.md @@ -61,6 +61,10 @@ You cannot declare a field, a property, an event, or the return type of a method Because the and methods on anonymous types are defined in terms of the `Equals` and `GetHashCode` methods of the properties, two instances of the same anonymous type are equal only if all their properties are equal. +> [!NOTE] +> The default accessibility level of an anonymous type is `internal`, hence two anonymous types defined in different assemblies are not of the same type. +> Therefore instances of anonymous types can't be equal to each other when defined in different assemblies, even when having all their properties equal. + Anonymous types do override the method, concatenating the name and `ToString` output of every property surrounded by curly braces. ``` From b8c3732d8227658c20a4e065382ce54a6b7ba830 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski Date: Thu, 23 Nov 2023 23:40:31 +0100 Subject: [PATCH 2/3] Add anonymous types to default access table and link to it --- docs/csharp/fundamentals/types/anonymous-types.md | 2 +- .../programming-guide/classes-and-structs/access-modifiers.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/csharp/fundamentals/types/anonymous-types.md b/docs/csharp/fundamentals/types/anonymous-types.md index 0f0e3c0cc2402..a26735ba817d8 100644 --- a/docs/csharp/fundamentals/types/anonymous-types.md +++ b/docs/csharp/fundamentals/types/anonymous-types.md @@ -62,7 +62,7 @@ You cannot declare a field, a property, an event, or the return type of a method Because the and methods on anonymous types are defined in terms of the `Equals` and `GetHashCode` methods of the properties, two instances of the same anonymous type are equal only if all their properties are equal. > [!NOTE] -> The default accessibility level of an anonymous type is `internal`, hence two anonymous types defined in different assemblies are not of the same type. +> The [default accessibility level](../../programming-guide/classes-and-structs/access-modifiers.md#default-access-summary-table) of an anonymous type is `internal`, hence two anonymous types defined in different assemblies are not of the same type. > Therefore instances of anonymous types can't be equal to each other when defined in different assemblies, even when having all their properties equal. Anonymous types do override the method, concatenating the name and `ToString` output of every property surrounded by curly braces. diff --git a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md index 1082166accabd..c1473666bf168 100644 --- a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md +++ b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md @@ -78,6 +78,7 @@ Delegates behave like classes and structs. By default, they have `internal` acce | `record` | internal | | `enum` | internal | | `interface` members | public | +| Anonymous types | internal | | [class, record, and struct members](./members.md) | private | For more details see the [Accessibility Levels](../../language-reference/keywords/accessibility-levels.md) page. @@ -103,3 +104,4 @@ For more details see the [Accessibility Levels](../../language-reference/keyword - [class](../../language-reference/keywords/class.md) - [struct](../../language-reference/builtin-types/struct.md) - [interface](../../language-reference/keywords/interface.md) +- [Anonymous types](../../fundamentals/types/anonymous-types.md) From 51272d9e96641ffc7303b0a9605241509dfe5670 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 27 Nov 2023 10:44:50 -0500 Subject: [PATCH 3/3] Update docs/csharp/fundamentals/types/anonymous-types.md --- docs/csharp/fundamentals/types/anonymous-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/fundamentals/types/anonymous-types.md b/docs/csharp/fundamentals/types/anonymous-types.md index a26735ba817d8..c5f53fac5809c 100644 --- a/docs/csharp/fundamentals/types/anonymous-types.md +++ b/docs/csharp/fundamentals/types/anonymous-types.md @@ -62,7 +62,7 @@ You cannot declare a field, a property, an event, or the return type of a method Because the and methods on anonymous types are defined in terms of the `Equals` and `GetHashCode` methods of the properties, two instances of the same anonymous type are equal only if all their properties are equal. > [!NOTE] -> The [default accessibility level](../../programming-guide/classes-and-structs/access-modifiers.md#default-access-summary-table) of an anonymous type is `internal`, hence two anonymous types defined in different assemblies are not of the same type. +> The [accessibility level](../../programming-guide/classes-and-structs/access-modifiers.md#default-access-summary-table) of an anonymous type is `internal`, hence two anonymous types defined in different assemblies are not of the same type. > Therefore instances of anonymous types can't be equal to each other when defined in different assemblies, even when having all their properties equal. Anonymous types do override the method, concatenating the name and `ToString` output of every property surrounded by curly braces.