这段代码其中有错,试试你能找出并调通不?
using System;
//using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace TestIterator1
{
//定义集合类
public class Tokens : IEnumerable
{
private string[] elements;
//构造函数
Tokens(string source,char[] delimiters )
{
elements = source.Split(delimiters);
}
public IEnumerator<char> GetEnumerator()
{
return new TokenEnumerator(this);
}
private class TokenEnumerator : IEnumerator
{
private int position = -1;
private Tokens t;
public TokenEnumerator(Tokens t)
{
this.t = t;
}
public bool MoveNext()
{
if (position < t.elements.Length - 1)
{
position++;
return true;
}
else { return false; }
}
public void Reset()
{
position = -1;
}
public object Current
{
get { return t.elements; }
}
}
}
class Program
{
static void Main(string[] args)
{
Tokens f = new Tokens("This is a fucking~ well-done program!", new[] { ' ', '-' });
foreach (string item in f)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
}