I am unsure why I am getting the following error message:
Error CS0540 'Tilemap.IEnumerable.GetEnumerator()': containing type does not implement interface 'IEnumerable' enter image description here
Here is my code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TileMapper
{
class Tilemap<T>
{
//Tilemap implementation
private readonly T[,] tilemap;
public int Width { get; }
public int Height { get; }
public Tilemap(int width, int height)
{
this.Width = width;
this.Height = height;
this.tilemap = new T[width, height];
}
public T this[int x, int y]
{
get { return this.tilemap[x, y]; }
set { this.tilemap[x, y] = value; }
}
//Tilemap as collection
public int Count => this.Width * this.Height;
public IEnumerator<T> GetEnumerator()
{
for (int y = 0; y < this.Height; y++)
{
for (int x = 0; x < this.Width; x++)
{
yield return this[x, y];
}
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}
I've searched for similar errors but most just reference adding the
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
which is what is giving me the error.
Your class definition doesn't say it implements IEnumerable<T>
:
class Tilemap<T>: IEnumerable<T>
{
//...
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments