I want to make a table in console but all done I execute the program the error appears in the method AlunoLista()
, already tried to make changes but I can not get there.
static void Main(string[] args)
{
var client = new string[7, 7];
InsertData<ClientHeader>(client);
Console.Clear();
InsertData<ClientHeader>(client);
AlunoLista(client);
Console.ReadKey();
}
static int getInsertIndex(string[,] matrix)
{
for (int j = 0; j < matrix.GetLength(0); j++)
{
if (string.IsNullOrEmpty(matrix[j, 0])) return j;
}
return -1;
}
private static void InsertData<T>(string[,] matrix)
{
int n = getInsertIndex(matrix), id = 1;
matrix[n, 0] = Convert.ToString(id++);
int x = matrix.GetLength(1) - 1;
matrix[n, x] = "true";
for (var j = 1; j < matrix.GetLength(1); j++)
{
do
{
Console.Write($"\nInsert {GetHeader<T>(j)}: ");
matrix[n, j] = Console.ReadLine();
} while (string.IsNullOrEmpty(matrix[n, j]));
}
}
private static string GetHeader<T>(int i) => Enum.GetName(typeof(T), i);
static void AlunoLista(string[,] lista)
{
Console.Clear();
string linha = new String('-', 49);
int[] tamanho = new int[] { 4, 10, 10, 20,10,10,10 };
for (int i = 0; i < lista.GetLength(1); i++)
{
Console.WriteLine(linha);
Console.Write("|");
for (int j = 0; j < lista.GetLength(0); j++)
{
if (lista[j, i] != null) lista[j, i] = "";
string espaço =new string (' ', tamanho[j] - lista[j, i].Length);
Console.Write($"{lista[j, i]}{espaço}");
Console.Write("|");
}
Console.WriteLine();
}
Console.WriteLine(linha);
}
enum ClientHeader { Id, Name, Surname, Addres, CodPostal, Telephone, Email, State };
}
}