using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace arrays { class Program { static void Main(string[] args) { /* * Array * Array 2D */ // ** Array ** ------------------------------\ // model one string[] modelOne = new string[3]; modelOne[0] = "a"; modelOne[1] = "b"; modelOne[2] = "c"; // test code Console.WriteLine(); Console.WriteLine("Array model one:"); Console.WriteLine( " {0} {1} {2}", modelOne[0], modelOne[1], modelOne[2] ); // end --------------------------------------| // model tow -----------------------------------------\ string[] modelTow = new string[] { "a", "b", "c" }; // test code Console.WriteLine(); Console.WriteLine("Array model tow:"); Console.WriteLine( " {0} {1} {2}", modelTow[0], modelTow[1], modelTow[2] ); // end -----------------------------------------------| // model three -----------------------------------------\ string[] modelThee = { "a", "b", "c" }; // test code Console.WriteLine(); Console.WriteLine("Array model three:"); Console.WriteLine( " {0} {1} {2}", modelThee[0], modelThee[1], modelThee[2] ); // end -----------------------------------------------| // ** Array 2D ** -----------------------------------------\ int[,] array2D = { { 1, 2 }, { 3, 4 } }; // test code Console.WriteLine(); Console.WriteLine("Array 2D Example:"); Console.WriteLine( array2D[0, 0] + array2D[0, 1] + array2D[1, 0] + array2D[1, 1] ); // end -----------------------------------------------| // pro example -----------------------------------------\ string[,] arrayPro = { { " ", "*", " ", " ", " ", "*", " " }, { " ", " ", " ", "*", " ", " ", " " }, { "*", " ", " ", "*", " ", " ", "*" }, { " ", "*", " ", " ", " ", "*", " " }, { " ", " ", "*", "*", "*", " ", " " } }; // Test Code one Console.WriteLine(); Console.WriteLine("**pro example**"); Console.WriteLine(); Console.WriteLine("Test Code one:"); for (int iPro = 0; iPro < 5; iPro++) { for (int iPro2 = 0; iPro2 < 7; iPro2++) { Console.Write(arrayPro[iPro, iPro2]); } Console.WriteLine(); } // Test Code tow Console.WriteLine(); Console.WriteLine("Test Code tow:"); foreach (string n in arrayPro) { Console.Write(n); } // end -----------------------------------------------| // Test Code Console.ReadLine(); } } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more