如何打印二维数组在C#安慰 [英] How to print 2D array to console in C#

查看:382
本文介绍了如何打印二维数组在C#安慰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我dont't有这方面的任何代码,但我想知道我怎么能做到这一点。我使用Visual Studio 2010的C#如果该事项。



感谢



杰森


解决方案

 公共静态无效Print2DArray< T>(T [,]矩阵)
{
为(INT I = 0; I< matrix.GetLength(0);我++)
{
为(INT J = 0; J< matrix.GetLength(1); J ++)
{
Console.Write(矩阵[I,J] +\t);
}
Console.WriteLine();
}
}


I dont't have any code for this, but I do want to know how I could do this. I use visual studio 2010 C# if that matters.

Thanks

Jason

解决方案

    public static void Print2DArray<T>(T[,] matrix)
    {
        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                Console.Write(matrix[i,j] + "\t");
            }
            Console.WriteLine();
        }
    }

这篇关于如何打印二维数组在C#安慰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆