VB.net-> C #

Source: Internet
Author: User

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.