C#数组1
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { int[] a = { 1, 2, 3, 4, 5, 6 };//省略的数组声明方法 for (int i = 0; i < a.Length; i++) { Console.WriteLine("i={0},a={1}", i, a[i]); } int[] a1 = new int[3] { 3, 4, 5 };//最标准的数组声明方法 foreach (int item in a1) //遍历数组 { Console.WriteLine(item); } string[] a2 = new string[3] {"张三","赵四","王五" }; foreach (var item in a2)//VAR根据你给变量赋值来判定变量属于什么类型 { Console.WriteLine( item); } foreach (string item in a2) { Console.WriteLine(item); } } } }