public class Ex
{
public string example1{get;set;}
public string example2{get;set;}
public Test test{get;set;}
}
public class Test
{
public string example3 {get;set;}
public long[] arrayLong{get;set;}
}
我有List listEx,例如10个元素。如何获得arraylong?
long[] result = listEx.Select( x=> x.Test.Select(y =>y.arrayLong)).ToArray();
我只需要长[]如何解析它?
答案 0 :(得分:3)
使用function numbersOnly(arr){
for(var i = 0; i < arr.length; i++){
if(typeof arr[i] === "string"){
delete arr[i];
}
}
console.log(arr);
}
numbersOnly([1, "apple", -3, "orange", 0.5, 22, "hello", 6])
功能,将“收集”集合集合到一个集合。
SelectMany
来自MSDN:Enumerable.SelectMany Method
答案 1 :(得分:1)
您应该使用SelectMany
var outresult = listEx.SelectMany(t => t.Test.Select(s => s.arrayLong)).ToArray();