gpt4 book ai didi

c# - ConvertAll ExtensionMethod in List 怎么样?

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:42 25 4
gpt4 key购买 nike

我想为 ConvertAll 编写我的扩展方法List<T> 中的方法.我在下面这样写。

public static List<TOutput> MyConvertAll<TOutput>(this List<T> list, Converter<T, TOutput> converter)
{
}

但它给了我错误:

Error: The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

请问怎么写?

最佳答案

您必须声明类型参数 T。

public static List<TOutput> MyConvertAll<TOutput, T>(this List<T> list, Converter<T, TOutput> converter)
{
}

关于c# - ConvertAll ExtensionMethod in List<T> 怎么样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com