On-the-Fly Code and Object Initializers

You might often use object initializers to create objects instances in line; generating code on-the-fly is powerful. Consider the following declaration:

image

When you write this code, the Person class and its FirstName and LastName properties do not exist. At this point you can open the correction options and choose the Generate Class command. Visual Studio automatically associates the previous assignments to the class that is initialized in line and generates the appropriate members. Code generation for the previous code snippet produces the following result:

image

With a single mouse click you have accomplished a task that would normally require a couple more steps, as described in the previous section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.64.126