c# - F# List.map 在 C# 中等效?

标签 c# .net linq f#

在 C# 中是否有与 F# 的 List.map 函数等效的函数?即,对列表中的每个元素应用一个函数,并返回一个包含结果的新列表。

类似于:

    public static IEnumerable<TResult> Map<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> funky)
    {
        foreach (TSource element in source)
            yield return funky.Invoke(element);
    }

是否已经有内置的方式,或者我应该只编写自定义扩展?

最佳答案

这是 LINQ 的 Select - 即

var newSequence = originalSequence.Select(x => {translation});

var newSequence = from x in originalSequence
                  select {translation};

关于c# - F# List.map 在 C# 中等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1594000/

相关文章:

c# - 多返回语句奇怪?

.net - 在 C# 中使用模式进行 XML 解析

c# - 如何获得类似于此 tsql 查询的 lambda 查询?

c# - 如何将 Action 提取到成员函数中?

c# - Linq 到 SQL : Updating dataGridView after SubmitChanges isn't working

c# - 是否可以这样做。排序(p => p.ID);或类似的东西?

c# - System.AccessViolation 由于 Marshal.StructureToPtr

c# - 替换一个巨大的文本文件中的特定行

c# - 错误 :Index (zero based) must be greater than or equal to zero and less than the size of the argument list

c# - WinForms 上下文菜单 - 在某些部分未打开/检测底层控件