Mastering C# List: A Comprehensive Reference
Classified in Computers
Written on in
English with a size of 54.79 KB
Understanding the C# List<T>
- The List<T> is a collection of strongly typed objects that can be accessed by index and includes methods for sorting, searching, and modifying the list.
- It is the generic version of the ArrayList, found within the
System.Collections.Genericnamespace. - The List<T> performs faster and is less error-prone than the
ArrayList. - Because it is a generic collection, you must specify a type parameter for the data it stores.
Creating a List and Adding Elements
List<int> primeNumbers = new List<int>();
primeNumbers.Add(1); // Adding elements using Add() method
primeNumbers.Add(3);
primeNumbers.Add(5);
primeNumbers.Add(7);Using Collection Initializer Syntax
var bigCities = new List<string>()
{... Continue reading "Mastering C# List: A Comprehensive Reference" »