What is the benefit of simplified object initialization?

  • Thread starter Thread starter Robert in SF
  • Start date Start date
R

Robert in SF

Guest
I have code like this

var form = new GetDate();
form.Text = "Assigned";
form.PreviousDate = txtEntered.Tag as DateTime?;
form.txtDate.Text = txtAssigned.Text == string.Empty ? DateTime.Now.ToString("MM/dd hh:mm") : txtAssigned.Text;
form.ShowDialog();


Visual Studio would rather this code be like this

var form = new GetDate
{
Text = "Assigned",
PreviousDate = txtEntered.Tag as DateTime?
};
form.txtDate.Text = txtAssigned.Text == string.Empty ? DateTime.Now.ToString("MM/dd hh:mm") : txtAssigned.Text;
form.ShowDialog();
Ok, but why? The VS suggestion seems less readable to me. Is there a compiled benefit?

Continue reading...
 
Back
Top