List C# with Example



List C# with Example

List is a list of a given type. Items can be added, inserted, removed and addressed by index. 
using System.Collections.Generic; 
var list = new List() { 1, 2, 3, 4, 5 }; 
list.Add(6); 
Console.WriteLine(list.Count); // 6 
list.RemoveAt(3); 
Console.WriteLine(list.Count); // 5 
Console.WriteLine(list[3]); // 5 
List can be thought of as an array that you can resize. Enumerating over the collection in order is quick, as is 
access to individual elements via their index. To access elements based on some aspect of their value, or some 
other key, a Dictionary will provide faster lookup. 

0 Comment's

Comment Form

Submit Comment