Reputation: 25768
In Javascript(JQuery), we can use map method to convert an array to another using a callback method. This is a great advantage of FP.
I am wondering if we can do the same thing in C# or Java?
Upvotes: 3
Views: 93
Reputation: 17278
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.
Upvotes: 0
Reputation: 34359
One option is to use a projection with LINQ:
myCollection.Select(element => new MyOtherType { ... });
Upvotes: 5