Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c数组中的列之和_C#_Arrays_For Loop_Sum_Max - Fatal编程技术网

C# c数组中的列之和

C# c数组中的列之和,c#,arrays,for-loop,sum,max,C#,Arrays,For Loop,Sum,Max,我被如何计算每列的总和难住了,然后我想用最大值显示列总和。 我不确定是在已经存在的函数中使用一组嵌套函数,还是创建另一个存储列和结果的数组?矩阵也会对我所做的每一列进行修改。不要忘记声明int-iValue=0;和int y=0 static int[,] matrix ={ { 4, 6, 9, 2, 5, 7}, { 4, 7, 5, 3, 7, 5},

我被如何计算每列的总和难住了,然后我想用最大值显示列总和。
我不确定是在已经存在的函数中使用一组嵌套函数,还是创建另一个存储列和结果的数组?矩阵也会对我所做的每一列进行修改。不要忘记声明int-iValue=0;和int y=0

static int[,] matrix ={
                          { 4, 6, 9, 2, 5, 7},
                          { 4, 7, 5, 3, 7, 5},
                          { 4, 2, 6, 9, 1, 6}

                         };

static int rowLength = matrix.GetLength(0);
static int colLength = matrix.GetLength(1);       

public static void Main(string[] args) {
            displayMatrix();
            Console.ReadKey();

        }//end Main

static void displayMatrix() { // Display The matrix
for (int i = 0; i < rowLength; i++) {
                for (int j = 0; j < colLength; j++) {
                    Console.Write(string.Format("{0} ", matrix[i, j]));
                }
                Console.Write(Environment.NewLine + Environment.NewLine);
            }
        }// end displayMatrix

你在网上搜索过这个问题吗?这些问题都有流利的答案。最好在发送问题之前搜索问题。我在这里没有看到任何代码试图进行任何求和,更不用说识别和/或显示最大求和。我也不知道你说的嵌套函数是什么意思;在C语言中,唯一与此相关的是匿名方法,它可以在其他方法中声明,但不清楚这与您的问题有什么关系。的确,在SO和互联网上有很多关于矩阵和算术的例子,但是你的问题是如此模糊和不清楚,我甚至不确定你的哪一个会是你的重复。
    public void TryThis()
    {
        for (int x = 0; x < matrix.GetLength(1); x++)
        {
            for (y = 0; y < matrix.GetLength(0); y++)
            {
                iValue = iValue + matrix[y, x]; 
            }
            textBox1.Text =textBox1.Text+ ("Colum " + x + " Sum=" + iValue);
            iValue = 0;
        }
    }