0

I have problems to convert the following piece of code into vb.net because I am not so experienced with lambda expressions. Especially the last line is my problem. Teleric Code Converter doesn't help me because of the last line. Could somebody help me?

int[] numbers = { 1, 3, 4, 9, 2, 4 };
int numToRemove = 4;
int numIndex = Array.IndexOf(numbers, numToRemove);
numbers = numbers.Where((val, idx) => idx != numIndex).ToArray();
Jerodev
  • 32,252
  • 11
  • 87
  • 108

2 Answers2

3

Not used VB since VB6(!) - this works though:

    Dim numbers() = {1, 3, 4, 9, 2, 4}
    Dim numToRemove As Integer = 4
    Dim numIndex As Integer = Array.IndexOf(numbers, numToRemove)
    numbers = numbers.Where(Function(ByVal val, ByVal idx) idx <> numIndex).ToArray()

(That's just a disclaimer as the above might not be best practices etc!)

AndyP9
  • 596
  • 4
  • 6
0

Conversion with Telerik works if you store the output of the last line in a new variable. Then you get this:

Private numbers As Integer() = {1, 3, 4, 9, 2, 4}
Private numToRemove As Integer = 4
Private numIndex As Integer = Array.IndexOf(numbers, numToRemove)
Private result = numbers.Where(Function(val, idx) idx <> numIndex)
Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • The nature of the code suggests that these *probably* weren't meant to be fields (i.e. Private modifier instead of Dim). Also `result` isn't present in the original c# and where OP had stored the result in an array, you are storing them in an IEnumerable(Of Integer). `.ToArray()` would end it nicely (then you might as well put it back in `numbers` anyway). – djv Dec 05 '17 at 19:40