Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to convert this vb coding to c# coding.....

VB
Private Sub btnGetCheckedItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCheckedItems.Click
       Dim o As Object
       For Each o In clb1.CheckedItems
           Console.WriteLine(o.ToString)
       Next o
   End Sub
Posted

Understanding VB isn't that difficult if you know C#. I'm sure you could have worked this out with less effort than it took to post the question!
C#
private void btnGetCheckedItems_Click(object sender, EventArgs e)
{
    foreach (object o in clb1.CheckedItems)
        Console.WriteLine(o);
}
 
Share this answer
 
Comments
Lantei 8-Sep-10 6:40am    
Reason for my vote of 5
Purr-fect!
Use following link for VB.Net to C#.Net conversion.

http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
 
Share this answer
 
Comments
ganesan2510 8-Sep-10 5:27am    
thanks
Dalek Dave 8-Sep-10 5:37am    
Doesn't always work though.
Rahul.RK 8-Sep-10 5:38am    
yup..however for small code snippets it does...
C#
private void btnGetCheckedItems_Click(object sender, EventArgs e)
      {
          object o;
          foreach(o in clb1.CheckedItems)
          {
          Console.WriteLine(o.ToString());
          }
      }
 
Share this answer
 
v2
Comments
DaveyM69 8-Sep-10 5:49am    
As o isn't used outside the foreach there is no need to declare it outside. Declaring inside keeps the scope limited as it should be:
foreach(object o ...

Calling ToString() inside Console.WriteLine is not required as WriteLine calls ToString on any objects anyway to write them.
Toli Cuturicu 8-Sep-10 7:13am    
Reason for my vote of 3
Barely acceptable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900