Skip to content

Conversation

@drewnoakes
Copy link
Member

Use some newer language features to increase the signal/noise ratio in code samples used to describe generics in C#.

  • Make code shorter through auto properties.
  • Narrow scope of areas to remove boilerplate.
  • Use target-typed new.
  • Remove redundant constructor.

Note we could go further with the language features here (such as collection initializers) but as this seems like a very fundamental level article I thought it best to use more explicit forms.

These snippets are used in https://review.learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/generics?branch=main

Use some newer language features to increase the signal/noise ratio in code samples used to describe generics in C#.

- Make code shorter through auto properties.
- Narrow scope of <Snippet> areas to remove boilerplate.
- Use target-typed new.
- Remove redundant constructor.

Note we could go further with the language features here (such as collection initializers) but as this seems like a very fundamental level article I thought it best to use more explicit forms.

These snippets are used in https://review.learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/generics?branch=main
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @drewnoakes

This looks great. I'll :shipit: as soon as the build finishes.

@BillWagner BillWagner merged commit 1704b3b into main Nov 21, 2024
11 checks passed
@BillWagner BillWagner deleted the dev/drnoakes/generic-snippets branch November 21, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants