RecurrenceRule Class
A recurrence rule of an iCalendar object (RRULE, [RFC 5545] 3.3.10), such as FREQ=WEEKLY;BYDAY=MO,WE;COUNT=10.
public sealed class RecurrenceRuleExample
var rule = RecurrenceRule.Parse("FREQ=MONTHLY;BYDAY=-1FR;COUNT=3")!;
var occurrences = rule.GetOccurrences(new DateTime(2026, 1, 30, 17, 0, 0)).ToList();
Assert.Equal([new DateTime(2026, 1, 30, 17, 0, 0), new DateTime(2026, 2, 27, 17, 0, 0), new DateTime(2026, 3, 27, 17, 0, 0)], occurrences);Constructors
| Name | Description |
|---|---|
| RecurrenceRule() |
RecurrenceRule()
RecurrenceRule.cspublic RecurrenceRule()No documentation is available.
Properties
| Name | Description |
|---|---|
| ByDay | Gets the days of the week (BYDAY). |
| ByMonth | Gets the months, from 1 to 12 (BYMONTH). |
| ByMonthDay | Gets the days of the month, negative from the end (BYMONTHDAY). |
| BySetPosition | Gets the positions of the occurrences in each period, negative from the end (BYSETPOS). |
| Count | Gets or sets the number of occurrences, or null. |
| Frequency | Gets or sets the frequency. |
| Interval | Gets or sets the interval between the periods: 2 for every other week of a weekly rule. |
| OtherParts | Gets the parts the rule has that the members do not read (BYHOUR, BYMINUTE, BYSECOND, BYYEARDAY, BYWEEKNO, extensions), by name. They are written back; RecurrenceRule.GetOccurrences does not support them. |
| Until | Gets or sets the last date of the occurrences, or null. |
| WeekStart | Gets or sets the first day of the week (WKST). |
ByDay
RecurrenceRule.csByMonth
RecurrenceRule.csByMonthDay
RecurrenceRule.csGets the days of the month, negative from the end (BYMONTHDAY).
Property value
BySetPosition
RecurrenceRule.csGets the positions of the occurrences in each period, negative from the end (BYSETPOS).
Property value
Count
RecurrenceRule.csFrequency
RecurrenceRule.csInterval
RecurrenceRule.csOtherParts
RecurrenceRule.csGets the parts the rule has that the members do not read (BYHOUR, BYMINUTE, BYSECOND, BYYEARDAY, BYWEEKNO, extensions), by name. They are written back; RecurrenceRule.GetOccurrences does not support them.
public IDictionary<string, string> OtherParts { get; }Property value
Until
RecurrenceRule.csGets or sets the last date of the occurrences, or null.
public CalendarDateTime? Until { get; set; }Property value
WeekStart
RecurrenceRule.csMethods
| Name | Description |
|---|---|
| GetOccurrences(DateTime) | Returns the start times of the occurrences, from the first one: start (the DTSTART of the component), then the dates the rule gives, until RecurrenceRule.Count occurrences or RecurrenceRule.Until. A rule without an end has infinitely many occurrences: take the ones you need. |
| Parse(string) | Reads a rule. |
| ToString() | Returns the rule as it is written in a RRULE property. |
GetOccurrences(DateTime)
RecurrenceRule.csReturns the start times of the occurrences, from the first one: start (the DTSTART of the component), then the dates the rule gives, until RecurrenceRule.Count occurrences or RecurrenceRule.Until. A rule without an end has infinitely many occurrences: take the ones you need.
public IEnumerable<DateTime> GetOccurrences(DateTime start)Parameters
startDateTime- The start of the first occurrence. The occurrences have its time of day and its kind.
Returns
IEnumerable<DateTime> The start times of the occurrences, in order.
Exceptions
NotSupportedException- The rule has a frequency of less than a day, or a part of
RecurrenceRule.OtherPartsthat changes the occurrences (BYHOUR,BYMINUTE,BYSECOND,BYYEARDAY,BYWEEKNO).
Parse(string)
RecurrenceRule.csReads a rule.
public static RecurrenceRule? Parse(string value)Parameters
valuestring- The rule, such as
FREQ=MONTHLY;BYDAY=-1FR.
Returns
RecurrenceRule? The rule, or null when it is malformed or has no FREQ.