I am trying to convert a piece of code to C#, but I cannot get my head around it:
For iItem = LBound(arrItems) To UBound(arrItems)
If InStr(arrItems(iItem), strFieldName & "=") = 1 Then
strFindField = Mid(arrItems(iItem), Len(strFieldName) + 2)
Exit For
End If
Next
What’s up with the if statement?
That tool doesn’t seem to produce very idiomatic C#, so I will translate this for you manually to provide a contrast.
This should mimic what you’re doing here, but it’s a little difficult to tell what the intent of your loop is. Also, be aware that
.Substringwill throw an exception if you feed it a number that is out of its range, whileMidwill just return an empty string. Since it’s not clear how the return for this loop is being used, though, it’s difficult to say what is the most appropriate option for handling this semantic change.