TableCollection.Contains
Contents
[
Hide
]TableCollection.Contains method
Returns true if the specified item is found in this collection; otherwise, false.
public bool Contains(Table item)
Parameter | Type | Description |
---|---|---|
item | Table | the specified item to find. |
Return Value
true if the specified item is found in this collection; otherwise, false.
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