Func< T,TResult>之间有什么区别?和转换器< TInput,TOutput>? [英] What's the difference between Func<T, TResult> and Converter<TInput, TOutput>?

查看:93
本文介绍了Func< T,TResult>之间有什么区别?和转换器< TInput,TOutput>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看Func和Converter代表的签名,

Looking at the signatures for the Func and Converter delegates,

public delegate TResult Func<T, TResult>(T arg);
public delegate TOutput Converter<TInput, TOutput>(TInput input);

我正在努力寻找两者之间的区别。当然,如果我们重命名通用类型的参数,它们基本上是相同的东西?

I'm struggling to see the difference between the two. Surely, if we rename the generic type arguments, they essentially amount to the same thing?

可以解释为什么他们都存在吗?

Can anyone explain why they both exist, please?

推荐答案

没有区别。其存在的原因是历史性的。 转换器< T1,T2> 已经在.NET 2.0中可用,但是整个范围 Func<> 类型稍后添加。为了一致性,添加了 Func< T,TResult> ,但它的作用与 Converter< T1,T2>

There is no difference. The reason for their existence is historical. Converter<T1,T2> was already available in .NET 2.0, but a whole range of Func<> delegate types were added later on. For consistency, Func<T,TResult> was added, but it did the same thing as Converter<T1,T2>.

这篇关于Func&lt; T,TResult&gt;之间有什么区别?和转换器&lt; TInput,TOutput&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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