{"id":31,"date":"2016-02-10T16:29:18","date_gmt":"2016-02-10T16:29:18","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=31"},"modified":"2026-06-17T09:26:31","modified_gmt":"2026-06-17T08:26:31","slug":"arrays","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/memory\/arrays\/arrays","title":{"rendered":".Arrays"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">List or Array?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">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\n\n\n<h4 class=\"wp-block-heading\">Create Arrays<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tByte&#91;] MyArray;\t\t\t\t\/\/Declare a handle first\n\tMyArray = new Byte&#91;3];\t\t\/\/Create the array\n\n\t\/\/...do something\n\n\tMyArray = new Byte&#91;3];\t\t\/\/If you want you can replace by creating a new array<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or use this to declare it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tByte&#91;] MyArray = new Byte&#91;3];\t\t\/\/Declare and allocate space for the array<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or this to set values at creation<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tByte&#91;] MyArray = new Byte&#91;3] {10, 4, 7 };\n\n\tint&#91;] Values = {10, 27, 7, 12, 45};<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Creating an array of constants in a function call<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tSomeFunction(new byte&#91;] { 0x00, 0x01 });<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert array to string of values<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tMyString = String.Join(\",\", MyArray);           \/\/Output array as a string of values sperated with a comma<\/code><\/pre>\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":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-arrays"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/31","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=31"}],"version-history":[{"count":11,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":553,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/31\/revisions\/553"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}