Array.prototype.Map - C# IEnumerable 等价物
Array.prototype.Map - C# IEnumerable Equivalent
我不知道如何映射 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 = ??
int[] items = new int[] { 12, 23, 14, 15, 65, 66, 33 };
IEnumerable<string> ids = items.Select(x => $"post-{x}");
IEnumerable.Select()
相当于您的 map()
。
我不知道如何映射 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 = ??
int[] items = new int[] { 12, 23, 14, 15, 65, 66, 33 };
IEnumerable<string> ids = items.Select(x => $"post-{x}");
IEnumerable.Select()
相当于您的 map()
。