<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Manda on Medium]]></title>
        <description><![CDATA[Stories by Manda on Medium]]></description>
        <link>https://medium.com/@amandafitch?source=rss-a5d7f723d9ee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lxEkqATGWbE4t8ZMWrJWQA.jpeg</url>
            <title>Stories by Manda on Medium</title>
            <link>https://medium.com/@amandafitch?source=rss-a5d7f723d9ee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 10:16:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amandafitch/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Multi-dimensional arrays explained]]></title>
            <link>https://medium.com/@amandafitch/multi-dimensional-arrays-explained-b3400c8d49f1?source=rss-a5d7f723d9ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3400c8d49f1</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Manda]]></dc:creator>
            <pubDate>Thu, 06 Dec 2018 07:02:03 GMT</pubDate>
            <atom:updated>2018-12-09T22:45:35.278Z</atom:updated>
            <content:encoded><![CDATA[<h3>A different way to think about multidimensional arrays</h3><p>There is nothing complex about multi-dimensional arrays except for how we are taught to understand them. Let me explain.</p><p>So, what is a multi-dimensional array? Most training materials skip this simple question and start with a common example: create a table with rows and columns. No problem, we developers get this. It’s easy as pie! We have one horizontal dimension and one vertical dimension. That sounds like <em>two-dimensions</em>, so it must be a multi-dimensional array with two dimensions!</p><p>Not so fast, peeps!</p><p>This idea of a two-dimensional array seems to makes sense, right? Fine. Let’s add a third dimension. Again, no problem, right? We now have a horizontal dimension, a vertical dimension, and a depth dimension. That sounds like <em>three-dimensions</em>, so it must be a multi-dimensional array with three dimensions!</p><p>Feeling confident that you know what’s going on and I must be insane?</p><p>Fine, Let’s add a fourth dimension. So… where does it go? We’ve already covered horizontal, vertical, and depth. <em>Where does the pesky fourth dimension go???</em> Let’s not stop there. I want to create a multi-dimensional array with twenty dimensions! <em>Where do they all go???</em></p><p>The answer is deceptively simple.</p><p>If you are like me and many other developers who have relied on articles, books, and videos to understand multi-dimensional arrays, there is something important you should know. 95% of them are spreading the same crappy examples of what a multi-dimensional array <em>is</em>. These examples are only partially correct. You must retrain your brain.</p><h4>The answer to “what is a multi-dimensional array?”</h4><p>A multi-dimensional array is an array with depth. Each dimension of a multi-dimensional array represents <em>depth</em>. Not a horizontal plane, not a vertical plane. Just depth. In other words, a multi-dimensional array is a nested array. This means that you have an array within an array within an array.</p><p>Note: Different dimensions <em>can’t</em> exist side-by-side, but two instances of the same dimension <em>can</em> co-exist.</p><h4>Where do dimensions exist?</h4><ul><li>If you have a two-dimensional array, dimension 2 exists within dimension 1.</li><li>If you have a three-dimensional array, dimension 3 exists within dimension 2, dimension 2 exists within dimension 1.</li><li>If you have a four-dimensional array, dimension 4 exists within dimension 3, dimension 3 exists within dimension 2, and dimension 2 exists within dimension 1.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*ROtgtmO07oRkLZ4l.png" /></figure><p>Do you see the pattern? Good!</p><h4>Where do values exist?</h4><p>A multi-dimensional array has dimensions <em>and</em> values. The values are always stored in the lowest dimension like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*3auB9eZPjy1SPA2I.png" /></figure><p>At the beginning of this article, we discussed the two-dimensional array and tossed in an example of a table with columns and rows. Now that we know a dimension represents depth, not something vertical or horizontal, what are <em>columns and rows</em>?</p><p>Columns and rows don’t exist.</p><p>Don’t worry, all is not lost! Columns and rows don’t exist, but cells do. Inside a table cell, you can store it’s horizontal and vertical position. This is how a two-dimensional array is actually structured:</p><ul><li>Dimension 1: Table</li><li>Dimension 2: Cell</li><li>Values: Horizontal position of cell, Vertical position of cell</li><li>Values exists within Dimension 2. Dimension 2 exists within Dimension 1.</li><li>Horizontal position and Vertical position exists within Cell. Cell exists within Table.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*AphZr10iNTRvzYVZ.png" /></figure><h4>How can dimensions co-exist?</h4><p>In a multi-dimensional array, an instance of a dimension can exist more than once within another dimension. In the example below, Dimension 1 contains two instances of Dimension 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*ZhV7ltvmDljn0Evq.png" /></figure><p>Because dimensions are sorted by depth, you cannot put instances of two different dimensions beside each other. There is no way to have Dimension 1 directly contain an instance of Dimension 2 and Dimension 3. Only instances of Dimension 2 can exist within Dimension 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*3dEi1MGbTfSiE2NE.png" /></figure><h4>Multi-dimensional arrays in action</h4><p>Now that we understand that (a) Dimensions exist within each other, (b) Multiple instances of a dimension can exist beside each other, and (c) values can exist within the deepest dimension, let’s look at some examples of what’s going on in our code!</p><p>Note: these examples are created with C#</p><pre>// Example 1 (Long)<br>// three-dimensional array<br>// Dimension 3 exists in dimension 2. Dimension 2 exists in dimension 1. Values exist in dimension 1.<br>		<br>int[, ,] multiarray = new int[2, 1, 3] <br>{ <br>    // Dimension 1 Slot 0<br>    { <br>        // Dimension 2 Slot 0<br>        { <br>            325,  // Dimension 3 Slot 0<br>            4,    // Dimension 3 Slot 1<br>            51    // Dimension 3 Slot 2<br>        }<br>    },				<br>    // Dimension 1 Slot 1<br>    { <br>        // Dimension 2 Slot 0<br>        { <br>            17,   // Dimension 3 Slot 0 <br>            890,  // Dimension 3 Slot 1 <br>            9     // Dimension 3 Slot 2 <br>        } <br>    } <br>};</pre><pre>// Example 1 (Short)<br>// three-dimensional array<br>// Dimension 3 exists in dimension 2. Dimension 2 exists in dimension 1. Values exist in dimension 1.<br>		<br>int[, ,] multiarray = new int[2, 1, 3] { { {325,4,51} } , { {17,890,9} } };</pre><pre>// Example 2 (Short)<br>// two-dimensional array<br>int[,] multiarray = new int[2, 1]{ {9},{9} };</pre><pre>// Example 3 (Short)<br>// three-dimensional array<br>int[,,] multiarray = new int[3, 2, 1]{ {{9},{9}} , {{9},{9}} , {{9},{9}} };</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3400c8d49f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>