在 Javascript(JQuery) 中,我们可以使用 map 方法通过回调方法将一个数组转换为另一个数组。这是 FP 的一大优势。
我想知道我们是否可以在 C# 或 Java 中做同样的事情?
一种选择是使用带有 LINQ 的投影:
myCollection.Select(element => new MyOtherType { ... });
In C#, Array has the ConvertAll method that literally does what you are asking for.
However, it takes a delegate as the argument, so for a concise way of writing it you'll want to use a lambda expression, making it quite similar to the projection as suggested by devdigital.