c# - 显示二维数组行列计数器
问题描述
我想显示数组行和列计数器。希望你能理解我的问题。图片在底部。
char[,] arr = new char[4, 4]
{
{ '☺', '♣', '♦', '♠'},
{ '♥', '♫', '☼', '☺'},
{ '☺', '♣', '♦', '♠'},
{ '♥', '♫', '☼', '☺'},
};
int rowLength = arr.GetLength(0);
int colLength = arr.GetLength(1);
for (int i = 0; i < rowLength; i++)
{
for (int j = 0; j < colLength; j++)
{
Console.Write(string.Format("\t{0} ", arr[i, j]));
}
Console.Write(Environment.NewLine + Environment.NewLine);
}
Console.ReadLine();
输出:没有计数器的图像
代替:带计数器的图像
解决方案
我猜你需要查看行号和列号。您需要将它们添加到代码中才能看到它们。像这样的东西:
char[,] arr = new char[4, 4]
{
{ '☺', '♣', '♦', '♠'},
{ '♥', '♫', '☼', '☺'},
{ '☺', '♣', '♦', '♠'},
{ '♥', '♫', '☼', '☺'},
};
int rowLength = arr.GetLength(0);
int colLength = arr.GetLength(1);
Console.Write("\t");
for (int row =1; row<5; row++)
{
Console.Write(string.Format("\t{0}", row));
}
Console.Write(Environment.NewLine);
for (int i = 0; i < rowLength; i++)
{
Console.Write(string.Format("\t{0} ", i+1));
for (int j = 0; j < colLength; j++)
{
Console.Write(string.Format("\t{0} ", arr[i, j]));
}
Console.Write(Environment.NewLine + Environment.NewLine);
}
Console.ReadLine();
推荐阅读
- python - 如何防止 Saxon/C Python 绑定在另一个处于活动状态时尝试启动新的 java VM?(JNI_CreateJavaVM() 失败,结果:-5)
- automation - 自动化工具如何识别控件
- database - 如何修复 Postgres 上过时的 postmaster.pid 文件?
- python-3.x - 无监督学习中的 NaN 损失函数
- mysql - 即使键存在,Mysql ForeignKey 约束也会失败
- apache-spark-sql - Spark SQL 执行中核心的使用
- javascript - 多个脚本
- sql - 在 Oracle 中运行查询时收到相同的错误
- keycloak - 如何在 keycloak 主题中使用我自己的通用文件?
- amazon-web-services - AWS 是否在 Internet 上提供 EC2 使用报告?