Help needed in finding coordinate count
<p>I have an 8 X 8 matrix.  Now, The below coordinates are occupied</p>

<p><code>{ 6, 3 }, { 5, 5 }, { 3, 3 }....</code> What needs to be done is that, I need to build straight line </p>

<p>through these points and needs to count how many coordinates they have touched?</p>

<p>My program so far stands as </p>

<pre><code>private static void GetCount(int[,] Positions)
{

    int rcount = 8;
    int firstRow = Positions[0, 0];            

    for (int i = 1; i &lt; Positions.Length/2; i++)
    {              
       int currentRow = Positions[i, 0];
       if (currentRow != firstRow)
        {
          rcount += 8;
          firstRow = currentRow;
        }      
     }

     int cCount = 8;
     int firstCol = Positions[0, 1];

     for (int i = 1; i &lt; Positions.Length / 2; i++)
     {


        int currentCol = Positions[i, 1];
        if (currentCol != firstCol)
        {
            cCount += 8;
            firstCol = currentCol;
         }

      }
     int totalCount = rcount - cCount;
     Console.WriteLine(totalCount);

}
</code></pre>

<p>And I am invoking it as </p>

<pre><code>GetCount(new int[,] { { 6, 3 }, { 5, 5 }, { 3, 3 } });
</code></pre>

<p>The output will be 40 here. (count will be 24 for each 3 unique rows i.e. 6,5,3 and count will be 16 for 2 unique columns i.e. 3 and 5... So, the total count is 24+16 = 40)
But I am getting the output as 48. </p>

<p><strong>Also  is it possible to do the porgram using one single loop?</strong></p>

<p>I am using C# 1.0</p>

<p>Edited</p>

<p>This does work</p>

<pre><code>List&lt;int&gt; lstRows = new List&lt;int&gt;();
            List&lt;int&gt; lstCols = new List&lt;int&gt;();
            int count = 0;

            //Get the unique rows and columns
            for (int i = 0; i &lt; marinePositions.Length / 2; i++)
            {
                if (!lstRows.Contains(marinePositions[i, 0])) lstRows.Add(Positions[i, 0]);
                if (!lstCols.Contains(marinePositions[i, 1])) lstCols.Add(Positions[i, 1]);
            }
            //get row count
            for (int i = 0; i &lt; lstRows.Count; i++) count += 8;
            //get column count
            for (int i = 0; i &lt; lstCols.Count; i++) count += 8;

            Console.WriteLine(count);
</code></pre>

<p>But need a much better one.. if possible using linq/lambda and no loop</p>

<p>Please help </p>
