Class WorkingTimeCollection
Contents
[
Hide
]WorkingTimeCollection class
Represents a collection of WorkingTimeCollection
objects.
public class WorkingTimeCollection : IList<WorkingTime>
Properties
Name | Description |
---|---|
Count { get; } | Gets the number of objects contained in this WorkingTimeCollection object. |
Item { get; set; } | Returns the element at the specified index. |
Methods
Name | Description |
---|---|
Add(WorkingTime) | Adds a new WorkingTime instance to this collection. |
Clear() | Removes all WorkingTime items from collection. |
Contains(WorkingTime) | Checks if the specified element is in the List. Performs a linear O(n) search. |
CopyTo(WorkingTime[], int) | copies a collection content into an Array, starting at a particular index |
GetEnumerator() | Returns an enumerator for this collection. |
Remove(WorkingTime) | Removes WorkingTime instance from this collection. |
ToList() | Converts the WorkingTimeCollection object to a list of WorkingTime objects. |
Examples
Shows how to work with working time collection.
var project = new Project();
var calendar = project.Calendars.Add("Custom Calendar");
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Thursday));
calendar.WeekDays.Add(WeekDay.CreateDefaultWorkingDay(DayType.Friday));
var saturdayWorkingTimes = new List<WorkingTime>
{
new WorkingTime(8, 12),
new WorkingTime(13, 15)
};
var saturday = new WeekDay(DayType.Saturday);
foreach (var time in saturdayWorkingTimes)
{
saturday.WorkingTimes.Add(time);
}
// print working times of Saturday
Console.WriteLine("Saturday working period number: " + saturday.WorkingTimes.Count);
foreach (var time in saturday.WorkingTimes)
{
Console.WriteLine("From Time: " + time.From);
Console.WriteLine("To Time: " + time.To);
}
Console.WriteLine();
var sundayWorkingTimes = new List<WorkingTime>
{
new WorkingTime(10, 15)
};
var sunday = new WeekDay(DayType.Sunday, sundayWorkingTimes);
// print working times of sunday
List<WorkingTime> workingTimes = sunday.WorkingTimes.ToList();
Console.WriteLine("Sunday working period number: " + workingTimes.Count);
for (var index = 0; index < workingTimes.Count; index++)
{
var time = workingTimes[index];
Console.WriteLine("From Time: " + time.From);
Console.WriteLine("To Time: " + time.To);
}
Console.WriteLine();
calendar.WeekDays.Add(saturday);
calendar.WeekDays.Add(sunday);
foreach (var day in calendar.WeekDays)
{
Console.WriteLine(day.DayType + ": ");
// You can further traverse through working times and display these
foreach (var workingTime in day.WorkingTimes)
{
Console.WriteLine(workingTime.From);
Console.WriteLine(workingTime.To);
}
Console.WriteLine();
}
See Also
- class WorkingTime
- namespace Aspose.Tasks
- assembly Aspose.Tasks