简体   繁体   English

我如何在一行中显示二维数组中的一些元素?

[英]How i can display a few elements from two dimensional array in one line?

I'm trying to display an array in the form of a table, as I do in c ++, but it doesn't work correctly. 我正在尝试以表格形式显示数组,就像在c ++中一样,但是无法正常工作。

I was trying some format parameters on WriteLine(String, Object[]) syntax - "\\n" or "\\b", but when i use some parameter, cmd doesn't displaying anything. 我在WriteLine(String,Object [])语法上尝试了一些格式参数-“ \\ n”或“ \\ b”,但是当我使用某些参数时,cmd不会显示任何内容。

C# code which currently I'm trying. 我目前正在尝试的C#代码。

 for (int i = 0; i < 25; i++)
            {
                for (int j = 0; j < 25; j++)
                {
                    Console.WriteLine(Map[i, j]);
                }
                Console.WriteLine(" ");
            }

C++ code which I'm rewriting to C#. 我正在重写为C#的C ++代码。

for (int i = 0; i < 25; i++)
    {
        for (int j = 0; j < 25; j++)
        {
            cout << tab[i][j];
        }
        cout << endl;
    }

What I'm expecting: 我期望的是:

0 1 2 3 4 5 6 7 8 9 10 
1 1 2 3 4 5 6 7 8 9 10 
2 1 2 3 4 5 6 7 8 9 10 
3 1 2 3 4 5 6 7 8 9 10 
4 1 2 3 4 5 6 7 8 9 10 
5 1 2 3 4 5 6 7 8 9 10 
6 1 2 3 4 5 6 7 8 9 10 
7 1 2 3 4 5 6 7 8 9 10 
8 1 2 3 4 5 6 7 8 9 10 
9 1 2 3 4 5 6 7 8 9 10
10 1 2 3 4 5 6 7 8 9 10

What I'm getting (without format parameter): 我得到了什么(没有format参数):

0
1
2
3
4
5
6
7
8
9
10
1
2
3
...

( It's my first post ) (这是我的第一篇文章)

Just you made a little mistake Console.WriteLine instead of Console.Write 只是您犯了一个小错误Console.WriteLine而不是Console.Write

 for (int i = 0; i < 25; i++)
 {
      for (int j = 0; j < 25; j++)
      {
          Console.Write(Map[i, j]);
      }
      Console.WriteLine();
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#,如何在另一个二维数组中保存一个数组中元素的频率? - C#, how to save frequency of elements from one array in another, two-dimensional array? 添加两个一维数组并显示为二维数组 - to add two one dimensional array and display as two dimensional array 如何在C#中从二维矩形字符数组的一行创建一个字符串? - How do I create a string from one row of a two dimensional rectangular character array in C#? 从 c# 中二维动态数组的每一行的所有正元素创建一个新的一维数组 - Creating a new one-dimensional array from all positive elements of each row of a two-dimensional dynamic array in c# 如何在C#中的二维数组中找到一维数组 - How to find a one dimensional array in a two dimensional array in C# 如何声明二维字符串数组? - How can I declare a two dimensional string array? 如何使用索引数组返回一行中指定的数组元素? - How can I return array elements specified in one line using an array of indexes? 如何在二维数组C#中选择两个顺序元素? - How do I select two sequential elements in a two dimensional array C#? 如何跳过数组中的前几个元素? - How to skip first few elements from array? 如何显示两个列表的两个元素? - How can I display two elements of two list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM