0
Someone can explain me the list type in C?
I have tried to search here in solo learn but I haven't found nothing
3 Answers
0
List<T> is part of namespace System.Collections.Generic.
The T is a generic parameter without restriction, means you can pass any type.
Examples: List<int>, List<string>, List<int[]>, List<object>, List<List<string>>
Where arrays are fixed in length, list allow to add/insert and remove items. So we can change the size of it.
It stores its data in an array internally. When you add/insert items when the internal array is filled completely, it doubles the size of the array. The internal size is accessible via property Capacity.
Example: You have four items in your list and its capacity is four. When you add one item its capacity will be set to eight.
You can set an initial capacity via constructor parameter. This makes sense when you e.g. know that you are going to add multiple thousands of items, because it prevents a lot of copy operations. The internal array gets replaced on increasing capacity. All existing items get copied to the new one.
By default an array of four items gets created on first add.
0
Can you give me for example a site or something like that where I can learn how to use lists?
0
You find some explanation here in the C# Tutorial.
Also See MSDN: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=netcore-3.1