What kind of construction is this

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I just wonder what kind of construction is this when having this code
column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
column.DropDownWidth = 160;
column.Width = 90;
column.MaxDropDownItems = 3;
column.FlatStyle = FlatStyle.Flat;
surrounded with this { and }

I mean what is the difference if I instead have method CreateComboBoxColumn

like this

private DataGridViewComboBoxColumn CreateComboBoxColumn()
{
DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn()
{
column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
column.DropDownWidth = 160;
column.Width = 90;
column.MaxDropDownItems = 3;
column.FlatStyle = FlatStyle.Flat;
}
return column;
}
 
Hello!

I just wonder what kind of construction is this when having this code
     column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
     column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
     column.DropDownWidth = 160;
     column.Width = 90;
     column.MaxDropDownItems = 3;
     column.FlatStyle = FlatStyle.Flat;
surrounded with this { and }

I mean what is the difference if I instead have method CreateComboBoxColumn

like this

private DataGridViewComboBoxColumn CreateComboBoxColumn()
{
    DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn()
{
    column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
    column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
    column.DropDownWidth = 160;
    column.Width = 90;
    column.MaxDropDownItems = 3;
    column.FlatStyle = FlatStyle.Flat;

}
return column;
}

Hi,

It looks like a initialization, in C# 3.0 you can do it like:
MyObject o = new MyObject() { Property1="fg";};

now what I do not know if it works is prefixing the properties name
with the name of the variable it will hold. as a matter of fact it
should give you error because otherwise you could do something like:
string s;

MyObject o = new MyObject() { s="dfgdfgdfg"; Property1="fg";};

which IHMO is not valid.

I will test it in a moment though and will post back the results
 
Back
Top