在编写程序时,我们可以按照二维数组数组内容存储顺序,将其打印输出到控制台中,如果,我们想要将二维数组内容通过倒序的方式打印到控制台中,该如何实现呢?
关键代码:
internal class Program
{
static void Main(string[] args)
{
string[,] book = { { "《三国演义》", "罗贯中" },{ "《水浒传》", "施耐庵" },{ "《西游记》", "吴承恩" },{ "《红楼梦》", "曹雪芹" } };
Console.WriteLine("正序输出:");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write(book[i,j]);
}
Console.WriteLine();
}
Console.WriteLine("倒序输出:");
for (int i = 3; i >=0; i--)
{
for (int j = 1; j >=0; j--)
{
Console.Write(book[i,j]);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
评论