首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Array.prototype.Map - C# IEnumerable等效

Array.prototype.Map - C# IEnumerable等效
EN

Stack Overflow用户
提问于 2016-12-15 12:19:38
回答 1查看 675关注 0票数 0

我不知道如何映射c#中的字符串列表,

我能要一些类似的js吗?

代码语言:javascript
复制
var items = [12, 23, 14, 15, 65, 66, 33];

var ids = items.map(id => `post-${id}`);

但是在IEnumerable<string>中使用C#

代码语言:javascript
复制
IEnumerable<string> ids = Product.GetRelatedProductsIds();

var posts = ?? 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-15 12:45:51

代码语言:javascript
复制
int[] items = new int[] { 12, 23, 14, 15, 65, 66, 33 };

IEnumerable<string> ids = items.Select(x => $"post-{x}");

IEnumerable.Select()是您的map()等效项。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41164032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档