I recently read a piece of VB. Net code.
Select Case itemType
Case ListItemType. Header
Cell. Text = HeaderText
Case ListItemType. Item, ListItemType. AlternatingItem
AddHandler cell. DataBinding, AddressOf ItemDataBinding
Case ListItemType. EditItem
AddHandler cell. DataBinding, AddressOf EditItemDataBinding
Dim DDL As New DropDownList
Cell. Controls. Add (DDL)
End Select
I want to translate this code into C # And encountered two problems. 1. When a switch statement is used, the same code is executed in two cases. In VB.net, it is OK to separate the Code with commas (,) (Case ListItemType. item, ListItemType. alternatingItem), but C # does not seem to have such a syntax. today, I accidentally saw a piece of code and found that it would be okay to write a connection case without a break. 2. About AddHandler cell. the description of DataBinding and AddressOf ItemDataBinding. After searching for information, it is found that the related events and methods in VB are written, similar to event subscription in C. the translated C # code is as follows:
Switch (itemType)
{
Case ListItemType. Header:
{
Cell. Text = HeaderText;
Break;
}
Case (ListItemType. Item ):
Case (ListItemType. AlternatingItem ):
{
Cell. DataBinding + = new System. EventHandler (ItemDataBinding );
Break;
}
// Case (ListItemType. AlternatingItem ):
//{
// Cell. DataBinding + = new System. EventHandler (ItemDataBinding );
// Break;
//}
Case (ListItemType. EditItem ):
{
Cell. DataBinding + = new System. EventHandler (EditItemDataBinding );
DropDownList ddl = new DropDownList ();
Cell. Controls. Add (ddl );
Break;
}
}
I wonder if you have any better ideas,