C# Collection Add
Description
Collection Add
adds an object to the end of the
Collection.
Syntax
Collection.Add
has the following syntax.
public void Add(
T item
)
Parameters
Collection.Add
has the following parameters.
item
- The object to be added to the end of the Collection. The value can be null for reference types.
Returns
Collection.Add
method returns
Example
/* ww w . jav a 2 s .c o m*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Demo
{
public static void Main()
{
Collection<string> myData = new Collection<string>();
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
Console.WriteLine("{0} myData:", myData.Count);
}
}
The code above generates the following result.