Isidro Padilla

Isidro Padilla

  • 1.4k
  • 319
  • 19.6k

How to convert VB.Net to CSharp?

Sep 11 2011 9:10 AM

Because my knowledge in c # are still very limited I am trying to convert the following routine VB.Net to C #. I have found several converters in the network. The problem is that converters provide me a code that works properly and I tried to change but I can not get it to work. The routine to convert is:

  Private Sub buttonFile_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles buttonFile.Click

  OpenMDialog.ShowDialog()

  If OpenMDialog.FileName.Length And  (OpenMDialog.FileName.EndsWith("mdb") Or  OpenMDialog.FileName.EndsWith("accdb")) Then

  lblFile.Text = OpenMDialog.FileName

  End If

  End Sub


and the result is as follows:

private void buttonFile_Click(object sender, EventArgs e)
{ this.OpenMDialog.ShowDialog();
if ((this.OpenMDialog.FileName.Length & -((this.OpenMDialog.FileName.EndsWith("mdb") | this.OpenMDialog.FileName.EndsWith("accdb")) > false)) > 0)
{
this.labelFile.Text = this.OpenMDialog.FileName;
}
}


When I try to compile, the compiler sends me the message siguiete:

"Expected )"

When I fix the problem of parenthesis, I get the new error that I do not know how to correct:

Error: Operator '>' can not be Applied to operands of type 'bool' and 'bool'

How do I change this "if" statement to avoid the error?

thank you all.



Translated into Spanish:

Debido a que mis conocimientos en c# aun son muy limitados estoy intentando convertir la siguiente rutina de VB.Net a C#.He encontrado varios conversores en la red. El problema es que los convertidores me proporcionan un código que no funciona y aunque he intentado modificarlo no logro hacerlo funcionar. La rutina a convertir es la siguiente:

Private Sub buttonFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonFile_Click

 OpenMDialog.ShowDialog()

 If OpenMDialog.FileName.Length And  (OpenMDialog.FileName.EndsWith("mdb") Or  OpenMDialog.FileName.EndsWith("accdb")) Then

 labelFile.Text = OpenMDialog.FileName

 End If

End


y el resultado el que viene a continuación:


private void buttonFile_Click(object sender, EventArgs e)
{
 this.OpenMDialog.ShowDialog();
 if ((this.OpenMDialog.FileName.Length &  -((this.OpenMDialog.FileName.EndsWith("mdb") |  this.OpenMDialog.FileName.EndsWith("accdb")) > false)) > 0)
 {
 this.labelFile.Text = this.OpenMDialog.FileName;
 }
}


Cuando intento la compilación, el compilador me envía el mensaje siguiete:

"Expected )"

Cuando corrijo el problema de los parentesis, me aparece el siguiente error que no se como correguir:

Error: Operator '>' cannot be applied to operands of type 'bool' and 'bool'

¿Cómo se cambia esta instrucción "if" para evitar el error?

gracias a todos.



Answers (2)