{"id":651,"date":"2016-11-23T21:39:51","date_gmt":"2016-11-23T21:39:51","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=170"},"modified":"2022-09-13T15:02:57","modified_gmt":"2022-09-13T14:02:57","slug":"arrays-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/memory-uwp-programming-in-c\/arrays-memory-uwp-programming-in-c\/arrays-2","title":{"rendered":".Arrays"},"content":{"rendered":"<h4>\n\tList or Array?<\/h4>\n<p>If your going to be resizing your array as you add and remove items often using a list is best (resizing an array causes it to be copied). &nbsp;If you need to be able to access array elements by index (rather than using for each) then use an array. &nbsp;If you need both then you can use a list to create the final set of objects and then convert it to an array, or just use an array.<\/p>\n<h4>\n\tCreate Arrays<\/h4>\n<pre><code>\n\tbyte[] MyArray;\t\t\t\t\/\/Declare a handle first\n\tMyArray = new byte[3];\t\t\/\/Create the array\n\n\t\/\/...do something\n\n\tMyArray = new byte[3];\t\t\/\/If you want you can replace by creating a new array\n<\/code><\/pre>\n<p>or use this to declare it:<\/p>\n<pre><code>\n\tbyte[] MyArray = new byte[3];\t\t\/\/Declare and allocate space for the array\n<\/code><\/pre>\n<p>or this to set values at creation<\/p>\n<pre><code>\n\n\tbyte[] MyArray = new byte[3] {10, 4, 7 };\n\n\tint[] Values = {10, 27, 7, 12, 45};\n<\/code><\/pre>\n<h4>\n\tCreating an array of constants in a function call<\/h4>\n<pre><code>\n\tSomeFunction(new byte[] { 0x00, 0x01 });\n<\/code><\/pre>\n<h4>\n\t2 Dimensional Arrays<\/h4>\n<pre><code>\n\tstring[,] My2DimensionalArray;\n\tMy2DimensionalArray = new string[2,3];\n<\/code><\/pre>\n<h5>\n\tJagged 2 Dimensional Arrays<\/h5>\n<pre><code>\n\tstring[][] My2DimensionalArray;\n\tMy2DimensionalArray = new string[2][];\n\tMy2DimensionalArray[0] = new string[6];\n\tMy2DimensionalArray[1] = new string[4];\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>List or Array? If your going to be resizing your array as you add and remove items often using a list is best (resizing an array causes it to be copied). &nbsp;If you need to be able to access array elements by index (rather than using for each) then use an array. &nbsp;If you need [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[133],"tags":[],"class_list":["post-651","post","type-post","status-publish","format-standard","hentry","category-arrays-memory-uwp-programming-in-c"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":1173,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/651\/revisions\/1173"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}