Class TableCollection
Contents
[
Hide
]TableCollection class
Contains a list of Table
objects. Implements ICollection<Table> interface.
public class TableCollection : ICollection<Table>
Properties
Name | Description |
---|---|
Count { get; } | Gets the number of elements contained in this collection. |
IsReadOnly { get; } | Gets a value indicating whether this collection is read-only; otherwise, false. |
Methods
Name | Description |
---|---|
Add(Table) | Adds the specified item to this collection. |
Clear() | Removes all items from this collection. |
Contains(Table) | Returns true if the specified item is found in this collection; otherwise, false. |
CopyTo(Table[], int) | Copies the elements of this collection to the specified array, starting at the specified array index. |
GetEnumerator() | Returns an enumerator for this collection. |
Remove(Table) | Removes the first occurrence of a specific object from this collection. |
ToList() | Converts a table collection to a list of Table objects. |
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
- namespace Aspose.Tasks
- assembly Aspose.Tasks