c list add element code example

Example 1: c list add element

// Create a list  
List<string> AuthorList = new List<string>();  
  
// Add items using Add method   
AuthorList.Add("Mahesh Chand");

Example 2: c list add element

using System;
using System.Collections.Generic;
 
class Program {
    static void Main(string[] args) {
        //empty list
        List<int> nums = new List<int>();
 
        //add elements to list
        nums.Add(63);
        nums.Add(58);
        nums.Add(47);
         
        //print list
        foreach (int num in nums) {
            Console.WriteLine(num);
        }
    }
}
Run the above C# program. The three items shall be added to the list.

Output

63
58
47

Tags:

C Example