TableCollection.CopyTo
Contents
[
Hide
]TableCollection.CopyTo method
Copies the elements of this collection to the specified array, starting at the specified array index.
public void CopyTo(Table[] array, int arrayIndex)
Parameter | Type | Description |
---|---|---|
array | Table[] | the specified one-dimensional array to copy elements to |
arrayIndex | Int32 | the zero-based index of the specified array at which copying begins. |
Examples
Shows how to work with table collections.
var project = new Project(DataDir + "Project1.mpp");
Console.WriteLine("Is collection of tables read-only?: " + project.Tables.IsReadOnly);
// iterate over tables
Console.WriteLine("Print tables of " + project.Get(Prj.Name) + " project.");
Console.WriteLine("Table count: " + project.Tables.Count);
foreach (var tbl in project.Tables)
{
Console.WriteLine("Index: " + tbl.Index);
Console.WriteLine("Name: " + tbl.Name);
}
// add a new table
var tableToAdd = new Table
{
Name = "New Table",
ShowInMenu = true
};
project.Tables.Add(tableToAdd);
Console.WriteLine("The collection contains the new table?: " + project.Tables.Contains(tableToAdd));
// one can clear the collection in two ways
if (deleteOneByOne)
{
// copy tables into the array and delete them one by one
var tables = new Table[project.Tables.Count];
project.Tables.CopyTo(tables, 0);
foreach (var table in tables)
{
project.Tables.Remove(table);
}
}
else
{
// or one can clear a table collection completely
project.Tables.Clear();
}
// the collection can be converted into a plain list of tables
List<Table> list = project.Tables.ToList();
foreach (var table in list)
{
Console.WriteLine("Index: " + table.Index);
Console.WriteLine("Name: " + table.Name);
}
See Also
- class Table
- class TableCollection
- namespace Aspose.Tasks
- assembly Aspose.Tasks