时间:2019-03-17 标签:c#outputList>>到控制台
我想测试功能。和输出列表< list>到达控制台,
namespace test
{
class Program
{
static void Main(string[] args)
{
List<List<int>> MoveLeftForawrd(List<int> Gameboard, int Y, int X)
{
. . .
return PossibleMoves;
}
List<List<int>> test = new List<List<int>> { };
List<int> Gameboard = new List<int> { };
int Currentplayer = 1;
List<int> gameboard = new List<int> {
-1,0,-1,0,-1,0,-1,0,
0,-1,0,-1,0,-1,0,-1,
-1,0,-1,0,-1,0,-1,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1
};
Gameboard = gameboard;
test = MoveLeftForawrd(Gameboard, 5, 7);
test.ForEach(Console.WriteLine);
}
}
}
但我得到的只是在控制台中。
System.Collections.Generic.List`1[System.Int32]
告诉我,如何正确输出列表&lt; list&gt;到控制台?我将非常感谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您有一个列表列表:
因此您可以迭代每个列表,然后迭代该列表中的项目:
You have a list of lists:
So you could iterate over each list, and then iterate over the items in that list:
您可以尝试使用
string.join
和 linq 的捏合,以获取String
从list&lt; string&lt; string&gt;
:在这里,我们将每行的项目加入空间:
例如
{1,0,-1,0}
将为“ 1 0 -1 0”
,然后与< code> emoverition.newline 获得类似的东西
You can try using
string.Join
and pinch of Linq in order to getstring
fromList<string>
:Here we join items in each line with space:
e.g.
{1, 0, -1, 0}
will be" 1 0 -1 0"
and then join lines with
Environment.NewLine
to get something like您可以简单地使用分层 foreach 循环来完成此操作,例如
输出:
You can do this simply using layered foreach loops e.g.
Output: