Syntax Question, C# 2005

  • Thread starter Thread starter bstauffer
  • Start date Start date
B

bstauffer

I found the following code example in the Visual Studio help:

private void AddOutOfOfficeColumn()
{
DataGridViewCheckBoxColumn column = new
DataGridViewCheckBoxColumn();
{
column.HeaderText = ColumnName.OutOfOffice.ToString();
column.Name = ColumnName.OutOfOffice.ToString();
column.AutoSizeMode =
DataGridViewAutoSizeColumnMode.DisplayedCells;
column.FlatStyle = FlatStyle.Standard;
column.ThreeState = true;
column.CellTemplate = new DataGridViewCheckBoxCell();
column.CellTemplate.Style.BackColor = Color.Beige;
}

DataGridView1.Columns.Insert(0, column);
}

I am wondering what this means when the the curly braces are used
after the constructor of the DataGridViewCheckBoxColumn. Thanks in
advance.
 
In this case... nothing; it is probably an artefact of an "if" block
that got removed.

In the more general case, braces *used in this way* can be used to
scope variables, but that is about it. There are of course many other
brace meanings with blocks, delegates, etc.

Marc
 
I found the following code example in the Visual Studio help:

private void AddOutOfOfficeColumn()
{
DataGridViewCheckBoxColumn column = new
DataGridViewCheckBoxColumn();
{
column.HeaderText = ColumnName.OutOfOffice.ToString();
column.Name = ColumnName.OutOfOffice.ToString();
column.AutoSizeMode =
DataGridViewAutoSizeColumnMode.DisplayedCells;
column.FlatStyle = FlatStyle.Standard;
column.ThreeState = true;
column.CellTemplate = new DataGridViewCheckBoxCell();
column.CellTemplate.Style.BackColor = Color.Beige;
}

DataGridView1.Columns.Insert(0, column);
}

I am wondering what this means when the the curly braces are used
after the constructor of the DataGridViewCheckBoxColumn. Thanks in
advance.

Doesn't mean much of anything in this code. If a variable had been declared
within the curly braces, then its life would be scoped to the end of the
curly braces (or that's the way it worked in C++ and I assume C# is the
same). I suspect you saw this at
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcell.aspx
or one of the other articles that have that code example. Looks to me like
some automated tool was used to generate the C# code for the example,
possibly from the VB.NET code in the same example, and the tool didn't
properly handle the With/End With code in the VB.NET example. But that's
just a guess.
 
Doesn't mean much of anything in this code. If a variable had been declared
within the curly braces, then its life would be scoped to the end of the
curly braces (or that's the way it worked in C++ and I assume C# is the
same). I suspect you saw this athttp://msdn2.microsoft.com/en-us/library/system.windows.forms.datagri...
or one of the other articles that have that code example. Looks to me like
some automated tool was used to generate the C# code for the example,
possibly from the VB.NET code in the same example, and the tool didn't
properly handle the With/End With code in the VB.NET example. But that's
just a guess.

Thank you for the responses. I suspected the same but couldn't be
sure.
 
Back
Top