Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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);
}
}
}Advertisements