Adding to generic List
In this chapter you will learn:
Adding to List
The following code shows how to add elements a List.
using System;//from ja v a 2 s. c o m
using System.Collections;
using System.Collections.Generic;
class Sample
{
public static void Main()
{
//Create a List of Strings
//String-typed list
List<string> words = new List<string>();
words.Add("A");
words.Add("B");
words.AddRange(new[] { "C", "D" });
words.Insert(0, "A"); // Insert at start
words.InsertRange(0, new[] { "E", "F" });
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » List