Skip to main content

Convert to Initializer

Converts a class constructor call to an object initializer.

#Availability

Available from the context menu or via shortcuts:

  • when the cursor is placed on the name of the initialized object, provided that the following line assigns a value to any property of this object.

Note

If there are several lines in a row that assign values to properties of the initialized object, the initializer will include all these properties.

#Notes

#Examples

MyClass objVar = new MyClass();
objVar.prop1 = "value1";
objVar.prop2 = "value2";
objVar.id = 10;

Result:

MyClass objVar = new MyClass { prop1 = "value1", prop2 = "value2", id = 10 };

#Screenshot

rsConvertToInitializer