Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “与”的区别是什么;这是不可数的<;T>;项目“;及;这是T项;?_C#_Generics - Fatal编程技术网

C# “与”的区别是什么;这是不可数的<;T>;项目“;及;这是T项;?

C# “与”的区别是什么;这是不可数的<;T>;项目“;及;这是T项;?,c#,generics,C#,Generics,我在选择以下选项时感到困惑 public static Foo<T>(this IEnumerable<T> items) where T : XYZ public static Foo<T>(this T items) where T : IEnumerable<XYZ> publicstaticfoo(此IEnumerable项) 其中T:XYZ 公共静态Foo(此T项) 其中T:IEnumerable

我在选择以下选项时感到困惑

public static Foo<T>(this IEnumerable<T> items)
            where T : XYZ

public static Foo<T>(this T items)
       where T : IEnumerable<XYZ>
publicstaticfoo(此IEnumerable项)
其中T:XYZ
公共静态Foo(此T项)
其中T:IEnumerable
他们之间有什么区别?到目前为止,我没有发现任何不同


XYZ
是一个抽象类。

第一个示例方法是类实例的扩展方法,该类继承或是
IEnumerable
,其中T(泛型,例如
.Foo
)继承
XYZ

第二个方法用于类的实例,该类继承或为T,其中T继承
IEnumerable


那么,有什么不同呢?第一个方法接受一个
IEnumerable
,其类型的实例继承了
XYZ
。第二个方法只接受类型为
XYZ

IEnumerable
实例。您的第二个示例需要第二个类型参数:
Foo
@silkfire:我不这么认为。它在没有第二个类型参数的情况下工作。