Tuesday, February 7, 2012 7:44

VB.NET to C#

Tagged with:
Posted by on Thursday, September 2, 2010, 19:53
This news item was posted in .NET category and has 0 Comments so far.

I came across this syntax error – “Non-invocable member ‘System.Windows.Forms.Control.Controls’ cannot be used like a method” when converting a VB.NET project to C#  windows form application.
In C#, weshould use bracket(“[", "]“) to retrieve item from a collection instead of using the parenthesis as in VB.NET.
VB.NET ->TabControl1.Controls(1).Enabled = False
C#         -> this.TabControl1.Controls[1].Enabled = false;

Issue – “Operator ‘==’ cannot be applied to operands of type ‘method group’ and ‘System.Windows.Forms.DialogResult’”
if (SaveFileDialog1.ShowDialog == System.Windows.Forms.DialogResult.OK)
It is calling the ShowDIalog method not the value of the dialog
if (SaveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

Leave a Reply

You can leave a response, or trackback from your own site.