Skip to content

Fix CLS example: keep private field as UInt16 - #55954

Open
sharadvc wants to merge 1 commit into
dotnet:mainfrom
sharadvc:cursor/fix-cls-uint16-sample-49691-d302
Open

Fix CLS example: keep private field as UInt16#55954
sharadvc wants to merge 1 commit into
dotnet:mainfrom
sharadvc:cursor/fix-cls-uint16-sample-49691-d302

Conversation

@sharadvc

@sharadvc sharadvc commented Sep 11, 2026

Copy link
Copy Markdown

The language-independence article explains that only the public Age property must use a CLS-compliant type. The C# snippet for the corrected example incorrectly changed the private personAge field to Int16 as well.

This change keeps personAge as UInt16 and casts to Int16 in the public property getter.

Fixes #49691


Internal previews

File Preview link
samples/snippets/csharp/VS_Snippets_CLR/conceptual.clscompliant/cs/public2.cs Learn preview

Build report

The language-independence docs explain that only the public Age property
must use a CLS-compliant type. Leave the private personAge field as
UInt16 and cast when exposing the Int16 property.

Fixes dotnet#49691

Co-authored-by: Sharad. <sharadvc@users.noreply.github.com>
@sharadvc
sharadvc requested review from a team and BillWagner as code owners September 11, 2026 17:54
@dotnetrepoman dotnetrepoman Bot added this to the September 2026 milestone Sep 11, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates PR is created by someone from the .NET community. label Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typo in field's CLS compliance example

1 participant