using System;
class Program
{
static void Main()
{
// 定义一个整数数组
int[] numbers = new int[5] { 1, 2, 3, 4, 5 };
// 遍历数组并打印每个元素
foreach (int num in numbers)
{
Console.WriteLine(num);
}
// 获取数组的长度
Console.WriteLine("数组的长度是: " + numbers.Length);
// 修改数组中的元素
numbers[0] = 10;
Console.WriteLine("修改后的第一个元素是: " + numbers[0]);
// 定义一个多维数组
int[,] matrix = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
// 遍历多维数组
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
Console.Write(matrix[i, j] + " ");
}
Console.WriteLine();
}
}
}
int[] numbers = new int[5] { 1, 2, 3, 4, 5 }; 创建了一个包含5个整数的数组。foreach 循环遍历数组中的每个元素并打印出来。numbers.Length 获取数组的长度。numbers[0] = 10; 将第一个元素修改为10。int[,] matrix = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; 创建了一个2行3列的二维数组。for 循环遍历二维数组,并打印出每个元素。上一篇:c# hashtable
下一篇:c# json解析
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站