通用接口,IEnumerable
我有以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QQQ.Mappings
{
interface IExcess<T>
{
IEnumerable<string, T> getExcessByMaterialGroup(T[] data);
void Sort<TKey>(T[] data, Func<T, TKey> selector);
}
}
但我收到此错误,“使用泛型类型 'System.Collections.Generic.IEnumerable' 需要 '1' 类型参数”
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
没有标准的
IEnumerable
泛型类型接口,只有IEnumerable
(MSDN)。我相信您需要
IDictionary
( MSDN) 代替There is no standard
IEnumerable<T, K>
generic type interface, onlyIEnumerable<T>
(MSDN).I believe you are need
IDictionary<string, T>
(MSDN) instead您正在尝试从 getExcessByMaterialGroup 返回
IEnumerable
。IEnumerable
仅采用一个类型参数,而不是两个(String 和 T)。我的猜测是您想要返回类似IEnumerable>
的内容You are attempting to return
IEnumerable<string, T>
from getExcessByMaterialGroup.IEnumerable<T>
only takes one type parameter, not two (String and T). My guess is that you want to return something likeIEnumerable<KeyValuePair<String, T>>
这是你的问题,IEnumerable 只有 1 个通用参数。
您究竟想实现什么目标?
This is your problem, IEnumerable has only 1 generic argument.
What exactly are you trying to accomplish?
IEnumerable 仅接受单个类型参数。您应该将其声明为
IEnumerable
。IEnumerable only accepts a single type argument. You should be declaring that as
IEnumerable<T>
.IEnumerable 只有一个类型参数,但您指定了两个 (string, T)。您可能想要类似的内容:
如果该方法应该返回可枚举的字符串。
IEnumerable only has one type argument, yet you have specified two (string, T). You probably want something like:
if the method is supposed to return an enumerable of strings.
IEnumerable
存在,不存在双字典样式IEnumerable
。如果您正在寻找类似 KeyValue 的关系,请考虑
IEnumerable>
IEnumerable<T>
exists, there is no dual dictionary styleIEnumerable<T, U>
.If you're looking for a KeyValue like relationship, consider
IEnumerable<KeyValuePair<string, T>>
IEnumerable
是唯一的方法,没有IEnumerable
但您可以使用IDictionary
IEnumerable<T>
is the only method there is noIEnumerable<T,T>
but you can useIDictionary<T,T>