使用char []属性创建对象的实例

时间:2018-11-28 11:42:58

标签: c# oop object

我有一个具有char []属性的类,但是当我尝试创建它的实例时,出现错误。我的代码是这样的:

班级:

public class Board
{
    private char[] priFC;

    public Board(char[] priFC){
        this.priFC = priFC;
    }
...}

主要:

Board Tab = new Board(char[10]);

创建Tab时,我得到了一个无效的表达式术语char

1 个答案:

答案 0 :(得分:2)

在Main中,在创建Tablero实例时,传递char[]实例而不是char[10]

Tablero Tab = new Tablero(new []{'s','t','a','c','k','o','v','e','r','f','l','o','w'});

Tablero Tab = new Tablero(new char[10]);

char [] charInstance = new char[]{'s','t','a','c','k','o','v','e','r','f','l','o','w'};
Tablero Tab = new Tablero(charInstance);