{"id":170,"date":"2009-07-24T22:18:43","date_gmt":"2009-07-24T21:18:43","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=170"},"modified":"2009-07-24T22:18:43","modified_gmt":"2009-07-24T21:18:43","slug":"arrays","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/arrays\/","title":{"rendered":"Arrays"},"content":{"rendered":"<p>Arrays are ways of having a block of memory allocated to a single variable type, this allows for holding the national lottery numbers within an array of 6 instead of actually having 6 different variables, saves on variable overload<\/p>\n<pre lang=\"csharp\">\r\nint value1 = new int (1);\r\nint value2 = new int (2);\r\nint value3 = new int (3);\r\nint value4 = new int (4);\r\nint value5 = new int (5);\r\nint value6 = new int (6);\r\n<\/pre>\n<p>and instead you could just have<\/p>\n<pre lang=\"csharp\">\r\nint[] values = new int[6] {1,2,3,4,5,6};\r\n<\/pre>\n<p>This is example code of how to use arrays.<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\n\r\nclass arrays\r\n{\r\n       public static void Main()\r\n       {\r\n              \/\/ the [] means a array declaration, and when you create the new instance of a int you then define the size (3 in this case)\r\n              \/\/ if you wish to define the default values, then place these within the {} brackes\r\n              int[] arrayInt = new int[3] { 3,2,1};       \r\n              \r\n              \/\/ for each (integer in the array of integers assign to i)\r\n              foreach (int i in arrayInt)\r\n                     Console.WriteLine(i);\r\n\r\n              \/\/ to alter the values within the array, an array always starts at 0\r\n              arrayInt[0] = 20;\r\n              arrayInt[1] = 30;\r\n              arrayInt[2] = 40;\r\n\r\n              foreach (int i in arrayInt)\r\n                     Console.WriteLine(i);\r\n              return;\r\n       }\r\n}\r\n<\/pre>\n<p>Save as array.cs and then compile using either mono\/csc.exe. The output will be <\/p>\n<pre class=\"consoleoutput\">\r\n3\r\n2\r\n1\r\n20\r\n30\r\n40\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Arrays are ways of having a block of memory allocated to a single variable type, this allows for holding the national lottery numbers within an array of 6 instead of actually having 6 different variables, saves on variable overload int value1 = new int (1); int value2 = new int (2); int value3 = new &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/arrays\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arrays<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[14,398,13,400],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-c_sharp","tag-c-sharp","tag-linux","tag-mono","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}