ReSharper for Visual Studio Code 2026.1 Help

Code Syntax Style: Object Creation ('new()' vs 'new T()')

Starting with C# 9.0, you can create objects with the target-typed new operator without explicit type specification when the type can be inferred, that is List<string> _myList = new(); instead of List<string> _myList = new List<string>();.

Depending on the context, the optional type specification can either clutter your code with redundant information or, on the contrary, improve the readability.

Therefore, ReSharper provides two code style preferences for object creation expressions:

  • when the created type is evident from usage, like in the following cases:

    • Initializers of fields/constants/properties/events private Test field = new()

    • Initializers of local variables when an explicit type is preferred Test local = new()

    • Return values of expression-bodied members public List <Test> M() => new()

    • Values within array initializer new Test[] { new(), new() }

    • Values within collection initializer new List <Test> { new(), new() }

    • Default parameter values void M(TestStruct arg = new()) { }

  • when the created type is not evident (for example, in return statements).

ReSharper helps you enforce style preferences for object creation expressions in the existing code and takes your preferences into account when it produces new code with code completion and performs refactorings.

Enforce preferences for object creation expressions

By default, ReSharper highlights type specifications as redundant in evident cases and helps remove them:

ReSharper syntax style inspection: Use target-typed new

On the other hand, in non-evident cases ReSharper suggests explicitly specifying the created type:

ReSharper syntax style inspection: Specify created type

If you prefer another style for the new operator in your code, you can change the corresponding preferences.

Configure preferences for object creation expressions

You can configure syntax style settings via EditorConfig. These settings can be stored in .editorconfig files on different levels of your solution hierarchy. The files are normally put under VCS so that settings defined there are shared among the project team.

If you have used ReSharper for Visual Studio or JetBrains Rider on your computer, or have opened the current solution using these tools, ReSharper for Visual Studio Code will read and apply your syntax style settings from .DotSettings files. However, any settings configured via .editorconfig will take precedence.

Configure preferences for object creation style using EditorConfig

  1. Open the desired .editorconfig file.

  2. Add the required object creation style properties to the file. For example:

    object_creation_when_type_evident = explicitly_typed
03 March 2026