
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to add items to a list in C#?
Firstly, declare a list −
var teams = new List<string>();
To add items to a C# list, use the Add() method −
teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia");
You can try to run the following code to add items to a list in C# −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var teams = new List<string>(); teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia"); Console.WriteLine("Elements..."); foreach (var countries in teams) { Console.WriteLine(countries); } } }
- Related Articles
- How to Add Commas Between a List of Items Dynamically in JavaScript?
- How to Add Image into Dropdown List for each items?
- How do I order a list and add position to its items in MongoDB?
- How to Add Items to Hashtable Collection in C#
- How to remove items from a list in C#?
- How can I add items to a spinner in Android?
- How to add items in a JComboBox on runtime in Java
- How to add items to an array in java dynamically?
- How to randomize the items of a list in Python?
- How to add a list item in HTML?
- How to close list items with JavaScript?
- How to count the number of items in a C# list?
- How to add an item to a list in Kotlin?
- How to add dividers and spaces between items in RecyclerView?
- How to add items/elements to an existing jagged array in C#?

Advertisements