5 Şubat 2015 Perşembe

Arrays in C#


using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsolEra { class Program { static void Main(string[] args) { Csharp allows us to use numerous built-in classes for data manipulation and data storing purposes. Array is one of the built-in classes in C#. //An array is used for store a data collection in same type. That's important. An array might be hold Int type datas, String type datas, etc. To declare an array, we'll specify the type of it and use the square brackets []. int[] newArray; We have declared an Array with Integer type with this statement above. Since an array is an Object, we have to modify this statement with the new keyword. int[] newArray2 = new int[6]; The number we have set into square brackets (which is "6") specifies the number of elements that given array holds. In an array, we can set initial values by using the square brackets that we talked about. Note the initial values will be specified when the array has declared. string[] newArray3 = new string[4] { "Chicago", "İstanbul", "Virginia", "Los Angeles" }; in an array, we can omit the size declaration. string[] houseHold = new string[] { "Jade", "Janet", "Jessica" , "Jools" , "James" }; Further, we can omit the new keyword in declaration. double[] prices = { 5.1, 6.66, 3.1, 2.53}; Note the values of an array must be seperated with a comma. Each element has an index number. See above. string[] list = { "noob", "cybot", "Jade" }; Now, if we want to access the elements of the list array, we will use de index numbers of these elements. In arrays, the first element's index number is: 0 the second element's index number is: 1 the third element's index number is: 2 ... We'll use square brackets to call the elements with their index numbers. See above: Console.WriteLine(list[0]); Output is: noob Console.WriteLine(list[1]); Output is: cybot Console.WriteLine(list[2]); Output is: Jade } } }

Hiç yorum yok:

Yorum Gönder