ReSharper 2026.1 Help

Code inspection: 'with' expression is used instead of object initializer

This inspection reports with expressions used on a freshly created object when a normal object initializer would do the same job without cloning. If the left side is already new T() and has no meaningful initializer, cloning it first is unnecessary. A plain object initializer is shorter and clearer.

Example

var item = new Record() with { Value = 42, Name = "test" }; record Record { public int Value { get; init; } public string Name { get; init; } }
var item = new Record { Value = 42, Name = "test" }; record Record { public int Value { get; init; } public string Name { get; init; } }

Quick-fix

Replace the with expression with an object initializer.

01 April 2026