像碰到下面标红的代码的情况该怎么办?原因是IEnumerator<T>又继承了IEnumerator 泛型和非泛型都各有一个Current
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Runtime.InteropServices;
namespace delete2
{
class Program
{
static void Main(string[] args)
{
}
}
class A : IEnumerator<string>
{
string a = “weikeli”;
public bool MoveNext()
{
return true;
}
public void Reset()
{
}
public object Current
{
get { return a; }
}
public string Current
{
get { return “liweike”; }
}
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Runtime.InteropServices;
namespace delete2
{
class Program
{
static void Main(string[] args)
{
}
}
class A : IEnumerator<string>
{
string a = “weikeli”;
public bool MoveNext()
{
return true;
}
public void Reset()
{
}
public object Current
{
get { return a; }
}
public string Current
{
get { return “liweike”; }
}
public void Dispose()
{ }
}
}
解决方案
15
15
应该按照下面这样写,object前面不能加修饰符,既不像属性,也不像接口里方法声明(根本就不是借口内),当需要自定义迭代器是,一直就这么用,但无法解释!
object IEnumerator.Current { get { return Current; } }