F#List.map是否等效于C#? [英] F# List.map equivalent in C#?

查看:66
本文介绍了F#List.map是否等效于C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中是否有等效于F#的List.map函数?也就是说,对列表中的每个元素应用函数,然后返回包含结果的新列表.

Is there an equivalent to F#'s List.map function in C#? i.e. apply a function to each element in the list and return a new list containing the results.

类似的东西:

    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);
    }

是否已经建立了内置方式,还是应该只编写自定义扩展名?

Is there already a built in way or should I just write the custom extension?

推荐答案

即LINQ的Select-即

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

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

这篇关于F#List.map是否等效于C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆