0
I wanted to make a table in console but all ran the program appears error in the method AlunoLista()
, I’ve tried to make changes but I can’t 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 };
}
}
Where does it go wrong? You need to give as much information as possible to help.
– Maniero
sorry it was not clear the error gives in variable: string space =new string (' ', size[j] - list[j, i].Length); in Alunolist Method
– ricardo
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero