Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update InlineArrayAttribute.xml #10036

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion xml/System.Runtime.CompilerServices/InlineArrayAttribute.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@
</Attributes>
<Docs>
<summary>Indicates that the instance's storage is sequentially replicated <see cref="P:System.Runtime.CompilerServices.InlineArrayAttribute.Length" /> times.</summary>
<remarks>This attribute can be used to annotate a <see langword="struct" /> type with a single field. The runtime replicates that field in the actual type layout as many times as is specified.</remarks>
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks

This attribute can be used to annotate a `struct` type with a single field. The runtime replicates that field in the actual type layout as many times as is specified.

> [!IMPORTANT]
> The default implementations of `Equals()` and `GetHashCode()` for types marked with this attribute throw <xref:System.NotSupportedException>. You must override both <xref:System.ValueType.Equals(System.Object)> and <xref:System.ValueType.GetHashCode%2A> if they will be used.
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

]]></format>
</remarks>
<example>The following example shows how to declare an inline array type with eight <see langword="float" /> values.
<code lang="csharp">
[InlineArray(8)]
Expand Down
6 changes: 5 additions & 1 deletion xml/System/ValueType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ The <xref:System.ValueType.Equals(System.Object)?displayProperty=nameWithType> m

The default implementation calls <xref:System.Object.Equals(System.Object)?displayProperty=nameWithType> on each field of the current instance and `obj` and returns `true` if all fields are equal.

> [!TIP]
The default implementation of <xref:System.ValueType.Equals(System.Object)?displayProperty=nameWithType> throws <xref:System.NotSupportedException> if <xref:System.Runtime.CompilerServices.InlineArrayAttribute> is applied to the type.
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

> [!IMPORTANT]
> Particularly if your value type contains fields that are reference types, you should override the <xref:System.ValueType.Equals(System.Object)> method. This can improve performance and enable you to more closely represent the meaning of equality for the type.

## Notes for the Windows Runtime
Expand Down Expand Up @@ -274,6 +276,8 @@ The <xref:System.ValueType.GetHashCode%2A> method applies to types derived from

For more information, see <xref:System.Object.GetHashCode%2A?displayProperty=nameWithType>, and <xref:System.Collections.Hashtable?displayProperty=nameWithType>.

The default implementation of <xref:System.ValueType.GetHashCode%2A?displayProperty=nameWithType> throws <xref:System.NotSupportedException> if <xref:System.Runtime.CompilerServices.InlineArrayAttribute> is applied to the type.
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

## Notes for the Windows Runtime

When you call the <xref:System.ValueType.GetHashCode%2A> method on a Windows Runtime structure, it provides the default behavior for value types that don't override <xref:System.ValueType.GetHashCode%2A>. This is part of the support that .NET provides for the Windows Runtime (see [.NET Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override <xref:System.ValueType.GetHashCode%2A>, even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit <xref:System.ValueType>.) However, they appear to have <xref:System.ValueType.ToString%2A>, <xref:System.ValueType.Equals%2A>, and <xref:System.ValueType.GetHashCode%2A> methods when you use them in your C# or Visual Basic code, and .NET provides the default behavior for these methods.
Expand Down