2D array to table in c#? -


i need put data table array , make array print formatted table in console. here's table got data http://puu.sh/oqv8f/7d982f2665.jpg ; need make array output rows , columns instead of list. have far:

 using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace zumba1 {     class zumba     {         static void main(string[] args)         { //recreated data in table zumba section, added each row, , each column.             string[,] schedule = new string [8, 6] { { "1:00", "3:00", "5:00", "7:00", "total", "", },                                  {"monday", "12", "10", "17", "22", "244",   },                                  {"tuesday", "11", "13", "17", "22", "252",},                                  {"wednesday", "12", "10", "22", "22", "264",},                                  {"thursday", "9", "14", "17", "22", "248",},                                  {"friday", "12", "10", "21", "12", "220",},                                  {"saturday", "12", "10", "5", "10", "148"},                                  {" ", " ", " ", " ", " ","1376",}};             foreach (string in schedule)             {                 console.writeline(i.tostring());             }             console.readkey();         }     } } 

any ideas?

foreach on [,] array gives elements list, noticed. in case need output follow:

for (int x0 = 0; x0 < schedule.getlength(0); x0++) {     (int x1 = 0; x1 < schedule.getlength(1); x1++)     {         console.write("{0}\t", schedule[x0, x1]);     }     console.writeline(); } console.readkey(); 

if want use foreach reason, can declare table [][] array. in both ways have create 2 loops:

string[][] schedule = new string[][] {                                     new string[] { "1:00", "3:00", "5:00", "7:00", "total", "", },                                     new string[] {"monday", "12", "10", "17", "22", "244",   },                                     new string[] {"tuesday", "11", "13", "17", "22", "252",},                                     new string[] {"wednesday", "12", "10", "22", "22", "264",},                                     new string[] {"thursday", "9", "14", "17", "22", "248",},                                     new string[] {"friday", "12", "10", "21", "12", "220",},                                     new string[] {"saturday", "12", "10", "5", "10", "148"},                                     new string[] {" ", " ", " ", " ", " ","1376",}         }; foreach (string[] line in schedule) {     foreach (string in line)         console.write("{0}\t", i);     console.writeline(); } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -