【发布时间】:2017-05-01 01:09:31
【问题描述】:
我不知道如何在c# 中映射字符串列表,
我能有类似这个js的东西吗:
var items = [12, 23, 14, 15, 65, 66, 33];
var ids = items.map(id => `post-${id}`);
但在C# 中使用IEnumerable<string>:
IEnumerable<string> ids = Product.GetRelatedProductsIds();
var posts = ??
【问题讨论】:
-
使用 LINQ:
var posts = ids.Select(s => "post-" + s) -
应该是什么结果,
posts是什么?那是 IDictionary 还是 IEnumerable?
标签: c# linq functional-programming ienumerable