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();
1

2 Answers 2

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!)

Sign up to request clarification or add additional context in comments.

Comments

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)

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.