既然空间有维度,
阵列也像是空间一样,
他是拥有维度的,
就让我们探索看看吧
X | 第0列 | 第1列 | 第2列 |
---|---|---|---|
第0行 | 1 | 2 | 3 |
第1行 | 4 | 5 | 6 |
第2行 | 7 | 8 | 9 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告一个二维阵列
int[,] Matrix = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
//开始照着阵列的样子排列吧
Console.Write(Matrix[0, 0]); Console.Write(Matrix[0, 1]); Console.WriteLine(Matrix[0, 2]);//第一行
Console.Write(Matrix[1, 0]); Console.Write(Matrix[1, 1]); Console.WriteLine(Matrix[1, 2]);//第二行
Console.Write(Matrix[2, 0]); Console.Write(Matrix[2, 1]); Console.WriteLine(Matrix[2, 2]);//第三行
Console.ReadKey();
}
}
}
结果:
123
456
789
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告一个二维阵列
int[,] Matrix = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
//使用双重回圈
//第一层,表示第几行
for(int i=0; i < 3; i++)
{
//第二层,表示第几列,由於变数i已用过所以习惯上会用j
for (int j = 0; j < 3; j++)
{
Console.Write(Matrix[i, j]+" ");
}
//我们这边要用一个特别的符号,换行符号"\n"在C#中表示换行
Console.Write("\n");
}
Console.ReadKey();
}
}
}
结果:
1 2 3
4 5 6
7 8 9
<<: 从 JavaScript 角度学 Python(14) - BMI 计算(2)
>>: 电子书阅读器上的浏览器 [Day15] 网页汇出成 epub 档案 (I)
今天讲的内容为制作Lobby的一些基本简单UI(下集)。 ...
此篇会介绍三种免费的 sass 编译方法。 Live Sass Compiler 这是一款免费 V...
前一篇我们谈到了事件系结的方法,在使用 事件系结(Event binding) 的时候,我们要先有一...
今天的教学为教大家如何将Unity build完之後安装到Android手机上面测试。 ...
身为一个App的开发新手常常会遇到一些莫名其妙又难以解决的问题,直到找到问题答案才发现根本是自己愚蠢...