本课目录

按位置读取列表中的值

根据位置读取列表里的值。这个例子取的是第二个数。

简单示例

初始状态4 7 9
结果7
Program.cs
using System;

int[] values = new int[] { 4, 7, 9 };
Console.WriteLine(values[1]);
输出
7
广告

生活中的例子

最近三次测得的温度依次是 18 度、21 度和 19 度。请显示第二次测得的温度。

初始状态18 21 19
结果21
Program.cs
using System;

int[] readings = new int[] { 18, 21, 19 };
Console.WriteLine(readings[1]);
输出
21
运行示例
终端
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
官方文档