private static void PrintAlternatives(String[] list)
{
int width, maxWidth;
int columns, column, posn;
String str;
// Determine the maximum string length, for formatting.
maxWidth = 0;
foreach (String a in list) {
if (a != null) {
width = a.Length;
if (width > maxWidth) {
maxWidth = width;
}
}
}
// Determine the number of columns.
width = Console.WindowWidth;
if (maxWidth > (width - 7)) {
columns = 1;
} else {
columns = width / (maxWidth + 7);
}
// Print the strings.
column = 0;
for (posn = 0; posn < list.Length; ++posn) {
str = list[posn];
if (str != null) {
Console.Write(str);
width = str.Length;
} else {
width = 0;
}
++column;
if (column < columns) {
while (width < maxWidth) {
Console.Write(' ');
++width;
}
Console.Write(" ");
} else {
Console.Write("\r\n");
column = 0;
}
}
if (column != 0) {
Console.Write("\r\n");
}
}