DEV Community

Cover image for Snippets in C#: Shorthand Instantiation
Matt Kenefick
Matt Kenefick

Posted on

1

Snippets in C#: Shorthand Instantiation

In order to eliminate some redundancy or increase readability, you can shrink the way you instantiate classes.

See the example below:

public class MyClass
{
// Shorthand instantiation
private readonly List<Foo> foos = new();
// Explicit instantiation
private readonly List<Bar> bars = new List<Bar>();
}
view raw example.cs hosted with ❤ by GitHub

Top comments (0)