The code below throws the following exception:
Error 1 Cannot implicitly convert type 'Clarity.DevTest.Exercises.ChessPosition' to 'System.Collections.Generic.IEnumerable< Clarity.DevTest.Exercises.ChessPosition>'. An explicit conversion exists (are you missing a cast?)
Can someone explain to me whats going wrong and why it cant return the result?
using System;
using System.Collections.Generic;
namespace Clarity.DevTest.Exercises
{
public class Exercise1
{
public IEnumerable<ChessPosition> GetLegalMoves(ChessPosition rookToMove, ChessPosition friendlyRook, ChessPosition enemyRook1, ChessPosition enemyRook2)
{
//create array to hold positions
ChessPosition[,] coords = new ChessPosition [8,8];
//set the Rooks into the correct places on the array
//eg rookToMove.X = 4, rookToMove.Y = 5, "R" would be places in 4,5
coords[rookToMove.X, rookToMove.Y] = "R";
coords[friendlyRook.X, friendlyRook.Y] = "F";
coords[enemyRook1.X, enemyRook1.Y] = "1";
coords[enemyRook2.X, enemyRook2.Y] = "2";
//throw new NotImplementedException();
ChessPosition result = new ChessPosition(4, 5);
return result;
}
}
public partial class ChessPosition
{
public ChessPosition(int x, int y)
{
//check to see if out of bounds
if (x < 1 || x > 8 || y < 1 || y > 8)
{
throw new ArgumentException("x and y must be in the range 1-8");
}
X = x;
Y = y;
}
public int X { get; set; }
public int Y { get; set; }
}
}