简体   繁体   中英

vb.net to c# code conversion

what would be its c# equivalent code

    Dim arLines() As String
Dim int i
    arLines = Split(RTB1.Text, vbNewLine)
    For i = 0 To UBound(arLines)
        ''# RTB2.Text = arLines(i)
    Next i 
string[] arLines;
arLines = RTB1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
for( int i = 0; i < arLines.Length; ++i )
{
    RTB2.Text = arLines[i];
}

That's done, but your code just wipes out the Text property of RTB2 each iteration (I'm assuming it is not supposed to be commented out as it is in your example), so you may as well just do this:

string[] arLines;
arLines = RTB1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
RTB2.Text = arLines[arLines.Length-1];    

The reason the online tools didn't help you was because you weren't sending valid VB in the first place.

Dim int i ''# will not compile

You need

Dim i As Integer ''# This will compile

Here's the C# equivalent

string arLines = null;
int i = 0;
arLines = Strings.Split(RTB1.Text, Constants.vbNewLine);
for (i = 0; i <= Information.UBound(arLines); i++) {
 RTB2.Text = arLines(i);
}

However, the code above (a direct VB to C# translation) isn't going to be much help for you either since RTB2.Text will simply be the LAST iteration of your for loop.

A great translation tool is found at
http://converter.telerik.com

There is a good translator at Developer Fusion - http://www.developerfusion.com/tools/convert/vb-to-csharp/

I've tried translating your code but the translator only works if your code compiles to start with (this is always an excellent place to start!). See suggestion from @rockinthesixstring :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM