TableCollection class

Contains a list of Table objects. Implements ICollection<Table> interface.

public class TableCollection : ICollection<Table>


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.


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.


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

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)
    // or one can clear a table collection completely

// 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