It’s not possible, and it’s not because it doesn’t make sense, it’s not necessary. Using your example, let’s assume you have an i that starts at 1, just access by subtracting 1 and it’s solved, you’ll 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 put in the Github for future reference.
If you can’t figure that out or solve the issue, or explain if that’s not what you need, then the problem is that you’re trying to do what you’re doing right now, beyond what you’re capable of doing and it’s not an answer here that 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, skip steps does not help.
Why do you need it? I see no reason for it.
– Maniero
I do, because I’m creating some fields dynamically and I’m testing a way to pass a List with the positions ready @Maniero.
– Master JR
Explain better, I haven’t seen the reasons yet, it doesn’t make a difference starting at 0 or 1, you can do everything you need. Give a real example.
– Maniero
@Masterjr Don’t just control the real index separately? If the indexes start at 0 and you need to control how 1 only increment by 1 each index...
– Jéf Bueno
Think of a screen that you need to insert phone fields dynamically without using JS. Imagine that you already have two fields created... then, the index is in 1, because the list goes from 0 to 1, so logically, you have two items.
– Master JR
...If I add a third field the index will be in 2 and if I pass a list with a headset model the position of it will be in 0 and I will need to pass with index 2. So I need to do this in order to test if it works... I know you could say: Oh, but you could simplify this using JAVA Script..., but I don’t know much and I saw problems when creating fields using JS in the validations part, because they don’t work and have to make a lot of modifications that in my case would take time...
– Master JR
I don’t understand anything at all. Anyway, I can’t imagine any reason to want to do this.
– Jéf Bueno
kkkkkkkkkkkkkkk If I could set this, it would be enough and solve my problem.
– Master JR
@Masterjr But can not, there is no such option. I ask what the goal because there is no reason to do this... Understanding the initial reason I could tell you a solution.
– Jéf Bueno
Got it... From all of you, thank you @Maniero :)
– Master JR
Have you thought about adding an empty item to your list before filling it, where it will take the 0 position. And when you start the
loop for
, start the index count by counting 1?– Igor Carreiro