
- 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
Adding an element to the List in C#
To add an element to the List, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(String[] args) { List<String> list = new List<String>(); list.Add("One"); list.Add("Two"); list.Add("Three"); list.Add("Four"); list.Add("Five"); list.Add("Six"); list.Add("Seven"); list.Add("Eight"); Console.WriteLine("Enumerator iterates through the list elements..."); List<string>.Enumerator demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { string res = demoEnum.Current; Console.WriteLine(res); } } }
Output
This will produce the following output −
Enumerator iterates through the list elements... One Two Three Four Five Six Seven Eight
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(String[] args) { List<int> list = new List<int>(); list.Add(50); list.Add(100); list.Add(150); list.Add(200); list.Add(250); list.Add(500); list.Add(750); list.Add(1000); list.Add(1250); list.Add(1500); Console.WriteLine("Enumerator iterates through the list elements..."); List<int>.Enumerator demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { int res = demoEnum.Current; Console.WriteLine(res); } } }
Output
This will produce the following output −
Enumerator iterates through the list elements... 50 100 150 200 250 500 750 1000 1250 1500
- Related Articles
- Adding an element into the Hashtable in C#
- Adding an element in an array using Javascript
- Adding K to each element in a Python list of integers
- Adding an element at the end of the array in Javascript
- Adding an element at the start of the array in Javascript
- Python program to covert tuple into list by adding the given string after every element
- Python program to convert tuple into list by adding the given string after every element
- Convert given array to Arithmetic Progression by adding an element in C++
- Adding an element at a given position of the array in Javascript
- Insert an element to List using ListIterator in Java
- C# program to find the index of an element in a List
- How do I add an element to an array list in Java?
- Adding Tuple to List and vice versa in Python
- How to remove an element from Array List in C#?
- How to remove an element from a list in Python?

Advertisements