Y
Y
Yura Mailler2020-12-29 18:34:59
C++ / C#
Yura Mailler, 2020-12-29 18:34:59

How to access a dynamic list by index?

Hello! Static lists can be accessed by index

int[] list;


      list[1] = 1; // как то так показал , ' 1 ' это индекс , если это так называется

But how to do the same only with dynamic?
If this is a very easy question, please treat me rudely, I recently studied dynamic lists for people and did not find what I was looking for on the Internet

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-12-29
@Yura111

But how to do the same only with dynamic?

If you mean System.Collections.Generic.List then also:
var list = new List<int>();
list[1] = 1; // но тут будет ошибка, тк на данный момент список слишком мал
list.Add(0); 
list.Add(1); // добавляем 0 и 1 в список - теперь в списке два элемента
list[1] = 2; // Теперь это ошибку не вызовет

A
Alexander Ananiev, 2020-12-29
@SaNNy32

You don't have a list, but an array. In an array, members are accessed by index. Same with dynamic arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question