How to set the Index of a List to start at 1 instead of 0 when populated

0

Whenever I populate a list in C #, as in the example below, as I add items, they are arranged starting from position 0 in index . If I add 5 items to my list, I will have 0, 1, 2, 3, and 4 positions. I need to make index start with 1 and get in the order 1, 2, 3, 4 and 5.

Is this possible?

List<PessoaContatoViewModel> lista = new List<PessoaContatoViewModel>();
lista.Add(pc);
    
asked by anonymous 26.10.2018 / 00:43

1 answer

4

It is not possible, nor is it because it does not make sense, it is not necessary. Using your example, let's assume you have an i that starts at 1, just access subtracting 1 and is solved, will access the first element as you want using a variable that starts at 1:

var i = 1;
var lista = new List<PessoaContatoViewModel>();
lista.Add(pc);
Write(lista[i - 1]);

I placed GitHub for future reference .

If you can not understand this or solve the question, or explain if this is not what you need, then the problem is to be trying to do what you are, right now, beyond what you can do and is not an answer here will solve the problem. Then the suggestion is to start doing simpler things, build knowledge step by step, to get to the point you need, skipping steps does not help.

    
26.10.2018 / 01:03