3

在 Javascript(JQuery) 中,我们可以使用 map 方法通过回调方法将一个数组转换为另一个数组。这是 FP 的一大优势。

我想知道我们是否可以在 C# 或 Java 中做同样的事情?

4

2 回答 2

5

一种选择是使用带有 LINQ 的投影

myCollection.Select(element => new MyOtherType { ... });
于 2013-07-07T13:43:52.353 回答
0

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.

于 2013-07-07T14:48:35.383 回答