Hi ,
I am learning C# and now am stuck with a simple prorgam.Tried googling
but didn't get an answer :(. The following program gives me three
compilation errors.Can anyone enlighten me? Thanks.
using System;
using System.Collections.Generic;
using System.Text;
namespace Collections
{
public class Tokens : IEnumerable<String>
{
private String[] elements;
Tokens(String source, char[] delimiters)
{
elements = source.Split(delimiters);
}
~Tokens()
{
}
public IEnumerator<StringGetEnumerator()
{
return new TokenEnumerator(this);
}
private class TokenEnumerator:IEnumerator<String>
{
private Int32 pos = -1;
private Tokens t;
public TokenEnumerator(Tokens tok)
{
t = tok;
}
public Boolean MoveNext()
{
if (pos < t.elements.Length - 1)
{
pos++;
return true;
}
else
{
return false;
}
}
public void Reset()
{
pos = -1;
}
public String Current
{
get { return t.elements[pos]; }
}
}
public static void Main()
{
Tokens f = new Tokens("This is my first C# program", new
char[] { ' ', '#' });
foreach (String s in f)
{
Console.WriteLine(s);
}
}
}
}
Error 1 'Collections.Tokens.TokenEnumerator' does not implement
interface member 'System.IDisposable.Dispose()'
Error 2 'Collections.Tokens.TokenEnumerator' does not implement
interface member 'System.Collections.IEnumerator.Current'.
'Collections.Tokens.TokenEnumerator.Current' is either static, not
public, or has the wrong return type
Error 3 'Collections.Tokens' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'Collections.Tokens.GetEnumerator()' is either static, not public, or
has the wrong return type.