public static class Analysis
{
*//I want to use my extensions methods here. To be more specific,
//I want to do like this:*
// var array = new int[]{1,2,3};
// var newArray = array.MyMethod();
}
public static class IEnumerableExtensions<T>
where T : IComparable
{
public static IEnumerable<Tuple<T, T>> MyMethod(this IEnumerable<T> source)
{
*//here is my method
//yield return .... ;*
}
}
这是我得到的错误:
扩展方法必须在非泛型静态类中声明
我希望能够将该方法用于int[]
, double[]
, DateTime[]
...
我不能在我的Analysis
班级中声明这个方法,因为它是非通用的。
从类中删除泛型参数并在方法上声明它:
public static class EnumerableExtensions
{
public static IEnumerable<Tuple<T, T>> MyMethod<T>(this IEnumerable<T> source)
where T : IComparable
{
*//here is my method
//yield return .... ;*
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句