Console write 2 strings from the list

1

I created a list in which I added 2 strings:

var lista = new List<string> {cliente.Nome, cliente.Sobrenome};

And in the end I wanted it to show like this:

Console.WriteLine(lista[0]);

But show only the name, why?

    
asked by anonymous 06.11.2017 / 16:33

1 answer

2

Because you are only ordering the first element, if you want to print the two elements, you have to do this explicitly. So:

WriteLine(${lista[0] - lista[1]});

Note that it is not writing the name, it is writing the element 0 of array . You know it's a name, but it does not know, it's just a string.

It's just a little weird wanting to put age as a string . Probably this whole idea is wrong, it does not look like it needs a list there, but I can not say without a larger context.

Is this too weird, add a list on it?

lista.AddRange(lista);

Something tells me that there should be several other errors in the code.

    
06.11.2017 / 16:40