Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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# IEnumerable.GetEnumerator()和IEnumerable<;T>;。GetEnumerator()为什么它们不';我没有新的关键字_C#_.net - Fatal编程技术网

C# IEnumerable.GetEnumerator()和IEnumerable<;T>;。GetEnumerator()为什么它们不';我没有新的关键字

C# IEnumerable.GetEnumerator()和IEnumerable<;T>;。GetEnumerator()为什么它们不';我没有新的关键字,c#,.net,C#,.net,在.net中,这就是IEnumerable和IEnumerable的定义。如果您定义了类似的内容(例如IMyInterface和IMyInterface),您会收到一条警告,要求在方法前面添加new,这怎么可能呢 (我知道为了实现,我必须显式地实现它,我只是询问定义接口,即使没有实现) 公共接口IEnumerable { IEnumerator GetEnumerator(); } 公共接口IEnumerable:IEnumerable { IEnumerator GetEnumerator()

在.net中,这就是
IEnumerable
IEnumerable
的定义。如果您定义了类似的内容(例如IMyInterface和IMyInterface),您会收到一条警告,要求在方法前面添加
new
,这怎么可能呢

(我知道为了实现,我必须显式地实现它,我只是询问定义接口,即使没有实现)

公共接口IEnumerable
{
IEnumerator GetEnumerator();
}
公共接口IEnumerable:IEnumerable
{
IEnumerator GetEnumerator();
}
范例

public interface IMy
    {
        IQueryable GetAll();
    }

public interface IMy<T> : IMy
    {
         IQueryable<T> GetAll();
    }
公共接口IMy
{
IQueryable GetAll();
}
公共接口IMy:IMy
{
IQueryable GetAll();
}
如前所述,它确实有与之关联的
new
关键字

从:

公共接口IEnumerable:IEnumerable
{
//返回此可枚举对象的IEnumerator。枚举器提供
//访问集合中所有内容的简单方法。
/// 
新的IEnumerator GetEnumerator();
}
如果让VisualStudio为它创建存根,它实际上将没有
new
关键字。这取决于您。

正如之前一样,它确实有与之相关联的
new
关键字

从:

公共接口IEnumerable:IEnumerable
{
//返回此可枚举对象的IEnumerator。枚举器提供
//访问集合中所有内容的简单方法。
/// 
新的IEnumerator GetEnumerator();
}

如果让VisualStudio为它创建存根,它实际上将没有
new
关键字。这取决于您。

什么让您认为它不是?您不能声明新的IEnumerable或IMy。您必须定义一个使用该接口的类并声明该新类。值得注意的是,在这种特殊情况下,“new”关键字从编译角度看没有任何作用。它只是为了消除编译器警告。换句话说,编译器说“当心,你在隐藏一个成员”,你告诉编译器“我知道我在隐藏它,不要警告我”。你为什么认为它不是?你不能声明一个新的IEnumerable或一个新的IMy。您必须定义一个使用该接口的类并声明该新类。值得注意的是,在这种特殊情况下,“new”关键字从编译角度看没有任何作用。它只是为了消除编译器警告。换句话说,编译器说“当心,你在隐藏一个成员”,你告诉编译器“我知道我在隐藏它,不要警告我”。这个问题不应该以“一个不能再复制的问题”来结束吗?我也没问题。我刚刚看到两个删除的答案,我想它需要一个。如果OP愿意,他甚至可以删除它。@DavidG我保留这个问题,以防其他人有同样的问题future@RezaRahmati我真的不介意这个问题出现在这里,我只是认为它应该被关闭而不是被回答。这个问题不应该被关闭为“一个不能再被复制的问题”吗?我也同意。我刚刚看到两个删除的答案,我想它需要一个。如果OP愿意,他甚至可以删除它。@DavidG我保留这个问题,以防其他人有同样的问题future@RezaRahmati我真的不介意这个问题出现在这里,我只是认为它应该关闭而不是回答。
public interface IMy
    {
        IQueryable GetAll();
    }

public interface IMy<T> : IMy
    {
         IQueryable<T> GetAll();
    }
public interface IEnumerable<out T> : IEnumerable
{
    // Returns an IEnumerator for this enumerable Object.  The enumerator provides
    // a simple way to access all the contents of a collection.
    /// <include file='doc\IEnumerable.uex' path='docs/doc[@for="IEnumerable.GetEnumerator"]/*' />
    new IEnumerator<T> GetEnumerator();
}