通用接口,IEnumerable

发布于 2024-12-06 13:08:31 字数 419 浏览 5 评论 0 原文

我有以下代码:

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' 类型参数”

I Have the following code:

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

But I'm getting this error, "Using the generic type 'System.Collections.Generic.IEnumerable' requires '1' type arguments"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

肥爪爪 2024-12-13 13:08:31

没有标准的 IEnumerable 泛型类型接口,只有 IEnumerable (MSDN)。
我相信您需要 IDictionary ( MSDN) 代替

There is no standard IEnumerable<T, K> generic type interface, only IEnumerable<T> (MSDN).
I believe you are need IDictionary<string, T> (MSDN) instead

无法言说的痛 2024-12-13 13:08:31

您正在尝试从 getExcessByMaterialGroup 返回 IEnumerableIEnumerable 仅采用一个类型参数,而不是两个(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 like IEnumerable<KeyValuePair<String, T>>

风流物 2024-12-13 13:08:31

这是你的问题,IEnumerable 只有 1 个通用参数。

IEnumerable<string, T>

您究竟想实现什么目标?

This is your problem, IEnumerable has only 1 generic argument.

IEnumerable<string, T>

What exactly are you trying to accomplish?

泅渡 2024-12-13 13:08:31

IEnumerable 仅接受单个类型参数。您应该将其声明为 IEnumerable

IEnumerable only accepts a single type argument. You should be declaring that as IEnumerable<T>.

听,心雨的声音 2024-12-13 13:08:31

IEnumerable 只有一个类型参数,但您指定了两个 (string, T)。您可能想要类似的内容:

IEnumerable<string> getExcessByMaterialGroup(T[] data);

如果该方法应该返回可枚举的字符串。

IEnumerable only has one type argument, yet you have specified two (string, T). You probably want something like:

IEnumerable<string> getExcessByMaterialGroup(T[] data);

if the method is supposed to return an enumerable of strings.

那伤。 2024-12-13 13:08:31

IEnumerable 存在,不存在双字典样式 IEnumerable

如果您正在寻找类似 KeyValue 的关系,请考虑 IEnumerable>

IEnumerable<T> exists, there is no dual dictionary style IEnumerable<T, U>.

If you're looking for a KeyValue like relationship, consider IEnumerable<KeyValuePair<string, T>>

就像说晚安 2024-12-13 13:08:31

IEnumerable 是唯一的方法,没有 IEnumerable 但您可以使用 IDictionary

IEnumerable<T> is the only method there is no IEnumerable<T,T> but you can use IDictionary<T,T>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文