Skip to content

Commit 2989372

Browse files
Emphasize about same anonymous types not being equal when from separate assemblies (#38421)
* Add note to anonymous types equality regarding separate assemblies * Add anonymous types to default access table and link to it * Update docs/csharp/fundamentals/types/anonymous-types.md --------- Co-authored-by: Bill Wagner <[email protected]>
1 parent ae98792 commit 2989372

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

docs/csharp/fundamentals/types/anonymous-types.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ You cannot declare a field, a property, an event, or the return type of a method
6161

6262
Because the <xref:System.Object.Equals%2A> and <xref:System.Object.GetHashCode%2A> 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.
6363

64+
> [!NOTE]
65+
> 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.
66+
> Therefore instances of anonymous types can't be equal to each other when defined in different assemblies, even when having all their properties equal.
67+
6468
Anonymous types do override the <xref:System.Object.ToString%2A> method, concatenating the name and `ToString` output of every property surrounded by curly braces.
6569

6670
```

docs/csharp/programming-guide/classes-and-structs/access-modifiers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Delegates behave like classes and structs. By default, they have `internal` acce
7878
| `record` | internal |
7979
| `enum` | internal |
8080
| `interface` members | public |
81+
| Anonymous types | internal |
8182
| [class, record, and struct members](./members.md) | private |
8283

8384
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
103104
- [class](../../language-reference/keywords/class.md)
104105
- [struct](../../language-reference/builtin-types/struct.md)
105106
- [interface](../../language-reference/keywords/interface.md)
107+
- [Anonymous types](../../fundamentals/types/anonymous-types.md)

0 commit comments

Comments
 (0)