DayTypeCollection class

Represents a collection of DayType objects.

public class DayTypeCollection : IList<DayType>


Count { get; }Gets the number of elements contained in this collection.
IsReadOnly { get; }Gets a value indicating whether if this collection is read-only; otherwise, false.
Item { get; set; }Returns or sets the element at the specified index.


Add(DayType)Adds the specified item to this collection.
Clear()Removes all items from this collection.
Contains(DayType)Returns true if the specified item is found in this collection; otherwise, false.
CopyTo(DayType[], int)Copies the elements of this collection to the specified array, starting at the specified array index.
GetEnumerator()Returns an enumerator for this collection.
IndexOf(DayType)Determines the index of the specified item in this collection.
Insert(int, DayType)Inserts the specified item at the specified index.
Remove(DayType)Removes the first occurrence of a specific object from this collection.
RemoveAt(int)Removes an item at the specified index.


Shows how to use a week day collection to define weekly calendar exception.

var project = new Project(DataDir + "WeeklyDayTypeException.mpp");
var calendar = project.Calendars.GetByUid(1);

foreach (var calendarException in calendar.Exceptions)
    Console.WriteLine("Exception Name: " + calendarException.Name);
    Console.WriteLine("Days of week count: " + calendarException.DaysOfWeek.Count);
    foreach (var dayType in calendarException.DaysOfWeek)
        Console.WriteLine("Day type: " + dayType);


var exc1 = calendar.Exceptions.ToList()[0];
if (!exc1.DaysOfWeek.IsReadOnly && exc1.DaysOfWeek.IndexOf(DayType.Monday) < 0)
    exc1.DaysOfWeek.Insert(0, DayType.Wednesday);

var exc2 = calendar.Exceptions.ToList()[1];
if (exc2.DaysOfWeek.Contains(DayType.Sunday))
    // delete a day type from "Exception 2" by day type

// delete a day type from "Exception 2" by index
Console.WriteLine("Remove " + exc2.DaysOfWeek[0] + " day type from exception by index...");

// Change exceptions (there is no exceptions in initial project data)
var exc4 = new CalendarException
                   Name = "Weekly Exception 2",
                   FromDate = new DateTime(2020, 4, 13),
                   ToDate = new DateTime(2020, 4, 18),
                   Occurrences = 3,
                   Type = CalendarExceptionType.Weekly


var exc3 = calendar.Exceptions.ToList()[2];

// remove all days of week for "Exception 3"

var dayTypes = new DayType[exc4.DaysOfWeek.Count];
exc4.DaysOfWeek.CopyTo(dayTypes, 0);

foreach (var dayType in dayTypes)

Console.WriteLine("Days of week for exception: " + exc3.Name);
foreach (var dayType in exc3.DaysOfWeek)
    Console.WriteLine("Day type: " + dayType);

See Also