我将以下代码转换为vb.net时遇到问题,因为我对lambda表达式不太熟悉。特别是最后一行是我的问题。由于最后一行,Teleric Code Converter对我没有帮助。有人能帮帮我吗?
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();
答案 0 :(得分:3)
从VB6开始不使用VB(!) - 但这有效:
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()
(这只是一个免责声明,因为上面可能不是最佳做法等等!)
答案 1 :(得分:0)
如果将最后一行的输出存储在新变量中,则使用Telerik进行转换。然后你明白了:
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)