C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# List<T>C# List<T> class is used to store and fetch elements. It can have duplicate elements. It is found in System.Collections.Generic namespace. C# List<T> exampleLet's see an example of generic List<T> class that stores elements using Add() method and iterates the list using for-each loop.
using System;
using System.Collections.Generic;
public class ListExample
{
public static void Main(string[] args)
{
// Create a list of strings
var names = new ListOutput: Sonoo Jaiswal Ankit Peter Irfan C# List<T> example using collection initializer
using System;
using System.Collections.Generic;
public class ListExample
{
public static void Main(string[] args)
{
// Create a list of strings using collection initializer
var names = new ListOutput: Sonoo Vimal Ratan Love
Next TopicC# HashSet
|