C# 在方法中显示二维数组

C# 在方法中显示二维数组,c#,arrays,C#,Arrays,我正在学习如何编程,我以前使用过其他语言,主要用于web,但c#至少对我来说有点难理解,而且msdn网站太复杂了,或者我不知道如何正确使用它。尝试构建解决数独难题的程序时,当我尝试在方法中显示二维数组时遇到了问题,出现了两个错误: using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[,] board

我正在学习如何编程,我以前使用过其他语言,主要用于web,但c#至少对我来说有点难理解,而且msdn网站太复杂了,或者我不知道如何正确使用它。尝试构建解决数独难题的程序时,当我尝试在方法中显示二维数组时遇到了问题,出现了两个错误:

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int[,] board = new int[9, 9] {{7, 2, 5, 8, 0, 4, 9, 1, 3},
                                      {0, 0, 0, 0, 3, 0, 0, 0, 4},
                                      {0, 0, 0, 0, 0, 1, 8, 2, 6},
                                      {0, 0, 9, 0, 0, 0, 0, 0, 7},
                                      {0, 1, 0, 6, 2, 8, 0, 4, 0},
                                      {2, 0, 0, 0, 0, 0, 5, 0, 0},
                                      {3, 6, 8, 4, 0, 0, 0, 0, 0},
                                      {0, 0, 0, 0, 7, 0, 0, 0, 8},
                                      {0, 0, 0, 0, 0, 2, 6, 9, 5}};

        DisplayBoard(board);

        List<int> missing = new List<int>();
        List<int> present = new List<int>();
        int temp = 0;

        for (int i = 0; i < 1; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                //Console.Write(board[i, j]);
                if (board[i, j] == 0)
                {
                    missing.Add(j);
                }
                else
                {
                    present.Add(board[i, j]);
                }

                if (present.Count == 8)
                {
                    for (int x = 0; x < present.Count; x++)
                    {
                        if (!present.Contains(x))
                        {
                            temp = x;
                        }
                    }

                    board[i, missing[0]] = temp;
                }
            }
            //missing.ForEach(Console.WriteLine);
        }
        DisplayBoard(board);
    }




    static void DisplayBoard(int[,])
    {
        for (int i = 0; i < 1; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                Console.Write(board[i, j]);
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
班级计划
{
静态void Main()
{
int[,]board=newint[9,9]{{{7,2,5,8,0,4,9,1,3},
{0, 0, 0, 0, 3, 0, 0, 0, 4},
{0, 0, 0, 0, 0, 1, 8, 2, 6},
{0, 0, 9, 0, 0, 0, 0, 0, 7},
{0, 1, 0, 6, 2, 8, 0, 4, 0},
{2, 0, 0, 0, 0, 0, 5, 0, 0},
{3, 6, 8, 4, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 7, 0, 0, 0, 8},
{0, 0, 0, 0, 0, 2, 6, 9, 5}};
显示板;
List missing=新列表();
列表当前=新列表();
内部温度=0;
对于(int i=0;i<1;i++)
{
对于(int j=0;j<9;j++)
{
//控制台写入(板[i,j]);
如果(电路板[i,j]==0)
{
缺失。添加(j);
}
其他的
{
(董事会[i,j]);
}
如果(present.Count==8)
{
对于(int x=0;x
您没有指定
DisplayBoard
方法的参数名称

static void DisplayBoard(int[,] board)
{
    for (int i = 0; i < 1; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            Console.Write(board[i, j]);
        }
    }
}
静态无效显示板(int[,]板)
{
对于(int i=0;i<1;i++)
{
对于(int j=0;j<9;j++)
{
控制台写入(板[i,j]);
}
}
}

错误是什么?循环
的目的是什么(int i=0;i<1;i++)
?现在完全没用了。我打赌你需要检查我在这里是否小于9。@SergeyBerezovskiy应该是I<9,但在测试时,我只尝试第一行。这有效,但为什么?我在这里调用函数时调用的数组是:DisplayBoard(board)@fakerismyguru
DisplayBoard
获取类型为
int[,]
的参数。您需要为该参数命名才能使用它(并避免编译错误)。