Display an array elements in 2 columns using the console
-
Suppose I have an array of n elements ( for example double or string) I want to display them in the console in 2 columns, having the same number of elements and keeping the order. if my
string[] my = new string[]{"a","b","c","d","e"}
I need to display a d b e c So first column a b c second column d e First and second column should be spaced It is like a menu Any smart idea?
-
Suppose I have an array of n elements ( for example double or string) I want to display them in the console in 2 columns, having the same number of elements and keeping the order. if my
string[] my = new string[]{"a","b","c","d","e"}
I need to display a d b e c So first column a b c second column d e First and second column should be spaced It is like a menu Any smart idea?
Something like this:
string[] my = new string[]{ "a", "b", "c", "d", "e" };
// Find the start index of the second column:
int midPoint = (my.Length / 2) + (my.Length & 1);for (int i = 0, j = midPoint; i < midPoint; i++, j++)
{
Console.WriteLine("{0}\t{1}", my[i], (j >= my.Length ? null : my[j]));
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Something like this:
string[] my = new string[]{ "a", "b", "c", "d", "e" };
// Find the start index of the second column:
int midPoint = (my.Length / 2) + (my.Length & 1);for (int i = 0, j = midPoint; i < midPoint; i++, j++)
{
Console.WriteLine("{0}\t{1}", my[i], (j >= my.Length ? null : my[j]));
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thks a lot