-6

For example:

int[,] multiArray = new int[2, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };

for (int Row = 0; Row < multiArray.GetLength(0); Row++)
{

    for (int Col = 0; Col < multiArray.GetLength(1); Col++)
    {
         TextBox.Text += multiArray[Row, Col] + "  ";
    }

    TextBox.Text += "\r\n";
}

The code above would produce:

1  2  3  4
5  6  7  8

How do I name my 2 rows as 2014, 2015 and name my 4 columns as January, April, July, October?

Value [2014, January] or index [0, 0] = 1,
Value [2014, April] or index [0, 1] = 2,
Value [2014, July] or index [0, 2] = 3,
Value [2014, October] or index [0, 3] = 4,
Value [2015, January] or index [1, 0] = 5,
Value [2015, April] or index [1, 1] = 6,
Value [2015, July] or index [1, 2] = 7,
Value [2015, October] or index [1, 3] = 8

And when I print out to TextBox by click a button would produce like the output below?

      January  April  July  October
2014    1      2      3     4   
2015    5      6      7     8
Tom
  • 16,842
  • 17
  • 45
  • 54
  • 3
    Welcome to StackOverflow! Your question is a little unclear. Arrays don't produce output. Please clarify what you are trying to achieve and show what you have tried so far. – René Vogt Aug 02 '16 at 09:07
  • If that is what you want, you should clarify that you want to convert the table to a 2-dimensional look up table/dictionary; if not: explain – Manfred Radlwimmer Aug 02 '16 at 09:08
  • Topic you want to google for is two-dimensional array. For example http://stackoverflow.com/questions/3814145/how-can-i-declare-a-two-dimensional-string-array – Ondrej Svejdar Aug 02 '16 at 09:08
  • here's are the issues with your request: 1) multi-types= you want a single array (more of a 2 dimensional array or a matrix) to contain both string and integers. 2) access = you want to get both rows and columns, and that cant be done with arrays, that's not how they work – MichaelThePotato Aug 02 '16 at 09:11
  • Please reopen my question as I have explained it clearer than before. Thanks. – Steven Chen Aug 02 '16 at 12:48

1 Answers1

0

Before trying out the WinForms start with CLI. I personally love manipulating string in CLI and when I'm sure I know what I'm doing then and only then do I translate it to WinForms.Looking at your question I assume you are looking to make some kind of calendar program.
Knowing that all people will learn best from examples,here is the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StackOverflow
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] months = { "Jan","Feb","Mar" };
            int[] years = { 2015, 2014, 2013 };
            int[,] important = { { 1, 2, 3 }, { 3, 4, 6 }, { 8, 16, 1 } };

            Console.Write("\t");
            foreach (string month in months)
            {
                Console.Write(month + "\t");
            }
            Console.WriteLine();
            Console.WriteLine();
            foreach (int year in years)
            {
                Console.Write(year.ToString());
                foreach (var month in months)
                {
                    Console.Write("\t" + important[years.ToList<int>().IndexOf(year),months.ToList<string>().IndexOf(month)].ToString());
                }
                Console.WriteLine();
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.ReadKey();

        }
    }
}
Zvonimir Rudinski
  • 435
  • 1
  • 5
  • 15