Visual Studio 2017 – Simplified Object Initialization

Visual Studio 2017 introduced code refactoring to simplify object initialization. Let’s say we have following class called Bar.


And here is how this class is consumed.


Notice the Gray dots under the new keyword in this picture. This is an indication that there is some code refactoring available. In order to view it, just click the Ctrl+. and it will bring up following pop-up.


As you can see in this image, the suggested change is to initialize the BarId and BarName properties using Object Initializer. If you choose to apply this suggestion, the updated code will look as follows.


Until next, happy debugging.


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s