I agree with John. Both versions compile to roughly the same IL, so it's just a matter of preference.
Looking at method two, you might expect it to do something like:
txtHolidayDescription.Text = string.Empty;
txtHolidayName.Text = txtHolidayDescription.Text;
txtHolidayDate.Text = txtHolidayName.Text;
But if you examine the compiled IL, you'll see that the property
get
accessor is never called. Instead, you simply get:
txtHolidayDescription.Text = string.Empty;
txtHolidayName.Text = string.Empty;
txtHolidayDate.Text = string.Empty;
You can demonstrate this with a simple class:
public class Foo
{
public string Text
{
get { throw new InvalidOperationException("Boo!"); }
set { }
}
}
static class Program
{
static void Main()
{
Foo x = new Foo();
Foo y = new Foo();
Foo z = new Foo();
x.Text = y.Text = z.Text = "Hello";
Console.WriteLine("Hooray!");
}
}
Running that code, no exception is thrown, which demonstrates that the
get
accessor is not called.