0
votes

I am trying to compile a c3 program but I keep on getting the error below.

Error CS1502: The best overloaded method match for string.Join(string, string[]) has some invalid arguments.

Error CS1503: Argument #2 cannot convert char[] expression to type string[]

for (int row = 0; row < 3; row++)
{
    char[] arr = new char[3];
    for (int col = 0; col < 3; col++)
    {
        if (board[row, col] == Player.None)
        {
            arr[col] = ' ';
        }
        else
        {
            arr[col] = board[row, col] == Player.P1 ? 'X' : 'O';
        }
    }
     
    Console.WriteLine("| {0} |", string.Join(" | ", arr));
3
Well everything is in the message : you're creating a char array while your method is expecting a string array... - Laurent S.

3 Answers

3
votes

The answer is very simple, arr is a char[] and not a string[].

try this

Console.WriteLine("| {0} |", string.Join(" | ", arr.Select(a => a.ToString())));
2
votes

You could either iterate the chars (as suggested by others) of the array or you could change the type of the array

for (int row = 0; row < 3; row++)
{
    var arr = new string[3];
    for (int col = 0; col < 3; col++)
    {
        if (board[row, col] == Player.None)
        {
            arr[col] = " ";
        }
        else
        {
            arr[col] = board[row, col] == Player.P1 ? "X" : "O";
        }
    }

    Console.WriteLine("| {0} |", string.Join(" | ", arr));
}
0
votes

As your arr is of type char[], you can use String(char[]) constructor to create string object instance

var strData= new string[]{new string(arr)};
Console.WriteLine("| {0} |", (string.Join(" | ", strData));