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 RecurrenceRule

Example

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

NameDescription
RecurrenceRule()

RecurrenceRule()

RecurrenceRule.cs
public RecurrenceRule()

No documentation is available.

Properties

NameDescription
ByDayGets the days of the week (BYDAY).
ByMonthGets the months, from 1 to 12 (BYMONTH).
ByMonthDayGets the days of the month, negative from the end (BYMONTHDAY).
BySetPositionGets the positions of the occurrences in each period, negative from the end (BYSETPOS).
CountGets or sets the number of occurrences, or null.
FrequencyGets or sets the frequency.
IntervalGets or sets the interval between the periods: 2 for every other week of a weekly rule.
OtherPartsGets 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.
UntilGets or sets the last date of the occurrences, or null.
WeekStartGets or sets the first day of the week (WKST).

Gets the days of the week (BYDAY).

public IList<RecurrenceDay> ByDay { get; }

Property value

IList<RecurrenceDay>

Gets the months, from 1 to 12 (BYMONTH).

public IList<int> ByMonth { get; }

Property value

IList<int>

Gets the days of the month, negative from the end (BYMONTHDAY).

public IList<int> ByMonthDay { get; }

Property value

IList<int>

BySetPosition

RecurrenceRule.cs

Gets the positions of the occurrences in each period, negative from the end (BYSETPOS).

public IList<int> BySetPosition { get; }

Property value

IList<int>

Gets or sets the number of occurrences, or null.

public int? Count { get; set; }

Property value

int?

Gets or sets the frequency.

public RecurrenceFrequency Frequency { get; set; }

Property value

RecurrenceFrequency

Gets or sets the interval between the periods: 2 for every other week of a weekly rule.

public int Interval { get; set; }

Property value

int

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.

public IDictionary<string, string> OtherParts { get; }

Gets or sets the last date of the occurrences, or null.

public CalendarDateTime? Until { get; set; }

Property value

CalendarDateTime?

Gets or sets the first day of the week (WKST).

public DayOfWeek WeekStart { get; set; }

Property value

DayOfWeek

Methods

NameDescription
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.cs

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.

public IEnumerable<DateTime> GetOccurrences(DateTime start)

Parameters

start DateTime
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.OtherParts that changes the occurrences (BYHOUR, BYMINUTE, BYSECOND, BYYEARDAY, BYWEEKNO).

Parse(string)

RecurrenceRule.cs

Reads a rule.

public static RecurrenceRule? Parse(string value)

Parameters

value string
The rule, such as FREQ=MONTHLY;BYDAY=-1FR.

Returns

RecurrenceRule? The rule, or null when it is malformed or has no FREQ.

Returns the rule as it is written in a RRULE property.

public override string ToString()

Returns

string The rule.