CSharp – Array
Array – foreach
using System; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { // <un array di stringhe> <nome array> = new string[numero elementi nell'array] string[] names = new string[2]; // array[indice] = assegna il valore names[0] = "Andrea"; names[1] = "Mario"; // visualizza tutti i valori contenuti foreach (string s in names) Console.WriteLine(s); Console.ReadLine(); } } }
The result is:
Andrea
Mario
Array – for
... for(int i = 0; i < names.Length; i++) Console.WriteLine("Item number " + i + ": " + names[i]); ...
Array – short syntax
... int[] numbers = new int[5] { 4, 3, 8, 0, 5 }; ... int[] numbers = { 4, 3, 8, 0, 5 }; ...
My website: http://www.lucedigitale.com
Reference: http://csharp.net-tutorials.com/basics/arrays/