C# 数组2D GetUpperBound(1)返回4而不是8

C# 数组2D GetUpperBound(1)返回4而不是8,c#,multidimensional-array,C#,Multidimensional Array,我是C#的新手,我正在尝试输出几个2D数组的历史记录,但是我不明白为什么GetUpperBound函数不能正常工作。我进行了调试,并在switch语句中显示了它返回4作为最后一列的任命 如果名为“约会”的矩阵有9列,为什么matrix.getupperbound(1)返回4?如果代码太多,我很抱歉,非常感谢您的帮助 enum clientHeader { Id_Client, Name, Type, Description, Name_CLient, Surname, Id_Spelc

我是C#的新手,我正在尝试输出几个2D数组的历史记录,但是我不明白为什么GetUpperBound函数不能正常工作。我进行了调试,并在switch语句中显示了它返回4作为最后一列的任命

如果名为“约会”的矩阵有9列,为什么matrix.getupperbound(1)返回4?如果代码太多,我很抱歉,非常感谢您的帮助

     enum clientHeader { Id_Client, Name, Type, Description, Name_CLient, Surname, Id_Spelciaty, Final_add,State };

            enum appointHeader { Id_Appoint, Name_Client, Surname,Type_Appoint,Date, Description, Id_Client, Final_add,State};

static void Main(string[] args)
            {
                Console.SetWindowSize(146, 45);

                string[,] animal = new string[30, 9];
                string[,] client = new string[30, 9];
                string[,] vet = new string[30, 9];
                string[,] appointment = new string[30, 9];
                string[,] obsRooms = new string[30, 5];
                string[,] typeAnimal = new string[30, 5];
                string[,] spelciaty = new string[30, 5];

                do { menuHistoric(animal, client, vet, obsRooms, appointment, spelciaty, typeAnimal); } while (true);
            }
            static void showHeader<T>(string[,] matrix)
            {
                int x = matrix.GetUpperBound(1), width = (tableWidth / x);
                Console.Clear(); 
                Console.WriteLine("\n");
                PrintLine();

                for (int i = 0; i < matrix.GetLength(1)-1; i++)
                {
                    Console.Write((GetHeader<T>(i)?.Length > width) ? $"{GetHeader<T>(i)?.Substring(0, width - 3) + ".." + "|".ToUpper()}" : $"{ GetHeader<T>(i)?.PadRight(width - (width - GetHeader<T>(i).Length) / 2).PadLeft(width).ToUpper()}|");
                }
                Console.WriteLine();
                PrintLine();
            }
            static int tableWidth = 143;

            static void PrintLine()
            {
                Console.WriteLine(new string('-', tableWidth));
            }
               static void menuHistoric(string[,] animal, string[,] client, string[,] vet, string[,] appointment, string[,] obsRooms, string[,] spelciaty, string[,] typeAnimal)
            {

                while (true)
                {
                    int optHist;

                    do
                    {
                        Console.Clear();
                        Console.WriteLine("\nInsert:\n\t[ 1 ] Visualize historic Clients");
                        Console.Write("\t[ 2 ] Visualize historic Appointments ");


                    } while (!int.TryParse(Console.ReadLine(), out optHist) || optHist < 0 || optHist > 7);

                    Console.Clear();
                    bool goBack = false;

                    switch (optHist)
                    {
                        case 1:
                           showHeader<clientHeader>(client);
                            menuReturn();
                            break;
                        case 2:
                           showHeader<appointHeader>(appointment);
                            menuReturn();
                            break;
                        case 0:
                            goBack = true;
                            break;

                    }
                    if (goBack) return;
                }
            }
            static void menuReturn()
            {
                Console.ReadKey();
                Console.Clear();
            }
            private static string GetHeader<T>(int i) => Enum.GetName(typeof(T), i);
enum clientHeader{Id_Client,名称,类型,描述,Name_Client,姓氏,Id_Spelciaty,Final_add,State};
enum Appointhader{Id_Appoint,姓名_Client,姓氏,类型_Appoint,日期,描述,Id_Client,最终添加,状态};
静态void Main(字符串[]参数)
{
控制台设置窗口大小(146,45);
字符串[,]动物=新字符串[30,9];
字符串[,]客户端=新字符串[30,9];
字符串[,]vet=新字符串[30,9];
字符串[,]约会=新字符串[30,9];
字符串[,]obsRooms=新字符串[30,5];
字符串[,]类型动物=新字符串[30,5];
字符串[,]spelciaty=新字符串[30,5];
do{menuHistoric(动物、客户、兽医、手术室、预约、专业、类型动物);}while(正确);
}
静态void showHeader(字符串[,]矩阵)
{
intx=matrix.GetUpperBound(1),width=(tableWidth/x);
Console.Clear();
Console.WriteLine(“\n”);
PrintLine();
对于(int i=0;iwidth)?$“{GetHeader(i)?.Substring(0,width-3)+.”“+”|“.ToUpper()}”:$“{GetHeader(i)?.PadRight(width-(width-GetHeader(i).Length)/2.padlight(width.ToUpper()}|”);
}
Console.WriteLine();
PrintLine();
}
静态int tableWidth=143;
静态无效打印行()
{
WriteLine(新字符串('-',tableWidth));
}
静态无效菜单历史(字符串[,]动物,字符串[,]客户端,字符串[,]兽医,字符串[,]约会,字符串[,]观察室,字符串[,]特殊,字符串[,]类型动物)
{
while(true)
{
内光学;
做
{
Console.Clear();
Console.WriteLine(“\n插入:\n\t[1]可视化历史客户端”);
Console.Write(“\t[2]可视化历史约会”);
}而(!int.TryParse(Console.ReadLine(),out optist)| | optist<0 | | optist>7);
Console.Clear();
bool-goBack=false;
开关(optHist)
{
案例1:
showHeader(客户端);
menuReturn();
打破
案例2:
展览员(委任);;
menuReturn();
打破
案例0:
goBack=true;
打破
}
如果(goBack)返回;
}
}
静态void菜单返回()
{
Console.ReadKey();
Console.Clear();
}
私有静态字符串GetHeader(inti)=>Enum.GetName(typeof(T),i);

您混淆了参数:
menuHistoric(动物客户兽医观察室预约、专业、类型动物)
静态无效菜单历史(字符串[,]动物,字符串[,]客户端,字符串[,]兽医,字符串[,]任命,字符串[,]障碍,字符串[,]特殊,字符串[,]类型动物)

也许可以通过使用
MenuHistoricArgument
的类/结构来避免大量参数:

    enum clientHeader { Id_Client, Name, Type, Description, Name_CLient, Surname, Id_Spelciaty, Final_add, State };

    enum appointHeader { Id_Appoint, Name_Client, Surname, Type_Appoint, Date, Description, Id_Client, Final_add, State };

    struct MenuHistoricArgument
    {
        public string[,] animal, client, vet, appointment, obsRooms, typeAnimal, spelciaty;
    }

    static void Main (string[] args)
    {
        Console.SetWindowSize(146, 45);

        MenuHistoricArgument menuArgs = new MenuHistoricArgument()
        {
            animal = new string[30, 9],
            client = new string[30, 9],
            vet = new string[30, 9],
            appointment = new string[30, 9],
            obsRooms = new string[30, 5],
            typeAnimal = new string[30, 5],
            spelciaty = new string[30, 5],
        };

        do {
            menuHistoric(menuArgs);
        } while (true);
    }
    static void showHeader<T> (string[,] matrix)
    {
        int x = matrix.GetUpperBound(1), width = (tableWidth / x);
        Console.Clear();
        Console.WriteLine("\n");
        PrintLine();

        for (int i = 0; i < matrix.GetLength(1) - 1; i++)
        {
            Console.Write((GetHeader<T>(i)?.Length > width) ? $"{GetHeader<T>(i)?.Substring(0, width - 3) + ".." + "|".ToUpper()}" : $"{ GetHeader<T>(i)?.PadRight(width - (width - GetHeader<T>(i).Length) / 2).PadLeft(width).ToUpper()}|");
        }
        Console.WriteLine();
        PrintLine();
    }
    static int tableWidth = 143;

    static void PrintLine ()
    {
        Console.WriteLine(new string('-', tableWidth));
    }
    static void menuHistoric (MenuHistoricArgument menuArgs)
    {

        while (true)
        {
            int optHist;

            do
            {
                Console.Clear();
                Console.WriteLine("\nInsert:\n\t[ 1 ] Visualize historic Clients");
                Console.Write("\t[ 2 ] Visualize historic Appointments ");


            } while (!int.TryParse(Console.ReadLine(), out optHist) || optHist < 0 || optHist > 7);

            Console.Clear();
            bool goBack = false;

            switch (optHist)
            {
                case 1:
                    showHeader<clientHeader>(menuArgs.client);
                    menuReturn();
                    break;
                case 2:
                    showHeader<appointHeader>(menuArgs.appointment);
                    menuReturn();
                    break;
                case 0:
                    goBack = true;
                    break;

            }
            if (goBack) return;
        }
    }
    static void menuReturn ()
    {
        Console.ReadKey();
        Console.Clear();
    }
    private static string GetHeader<T> (int i) => Enum.GetName(typeof(T), i);
enum clientHeader{Id_Client,名称,类型,描述,Name_Client,姓氏,Id_Spelciaty,Final_add,State};
enum Appointhader{Id_Appoint,姓名_Client,姓氏,类型_Appoint,日期,描述,Id_Client,最终添加,状态};
结构菜单历史辩论
{
公共字符串[,]动物、客户、兽医、预约、obsRooms、typeAnimal、spelciaty;
}
静态void Main(字符串[]参数)
{
控制台设置窗口大小(146,45);
MenuHistoricArgument menuArgs=新MenuHistoricArgument()
{
animal=新字符串[30,9],
client=新字符串[30,9],
vet=新字符串[30,9],
约会=新字符串[30,9],
obsRooms=新字符串[30,5],
typeAnimal=新字符串[30,5],
spelciaty=新字符串[30,5],
};
做{
menuHistoric(menuArgs);
}虽然(正确);
}
静态void showHeader(字符串[,]矩阵)
{
intx=matrix.GetUpperBound(1),width=(tableWidth/x);
Console.Clear();
Console.WriteLine(“\n”);
PrintLine();
对于(int i=0;iwidth)?$“{GetHeader(i)?.Substring(0,width-3)+.”“+”|“.ToUpper()}”:$“{GetHeader(i)?.PadRight(width-(width-GetHeader(i).Length)/2.padlight(width.ToUpper()}|”);
}
Console.WriteLine();
PrintLine();
}
静态int tableWidth=143;
静态无效打印行()
{
WriteLine(新字符串('-',tableWidth));
}
静态无效菜单历史(菜单历史辩论菜单)
{
while(true)
{
内光学;
做
{