VSO
VSO

Reputation: 12656

C# Single Pipe Syntax

var schedule = builder
    .OnDaysOfWeek(DayInterval.Mon | DayInterval.Wed | DayInterval.Fri)
    .HavingFrequency(FrequencyType.Weekly)
    .Create();

http://schedulewidget.azurewebsites.net/

What is the | syntax here, and more importantly how do I loop through a list of days and generate a varialbe to pass to: .HavingFrequence(myMagicVarHere).

I need something like: var myMagicVar = DayInterval.Mon | DayInterval.Wed | DayInterval.Fri, obviously that doesn't work.

Edit: Peeking defineition: public ScheduleBuilder HavingFrequency(FrequencyType type)

Upvotes: 4

Views: 524

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064014

| is "or", in the arithmetic / bitwise sense. It is often used with [Flags] enum declarations - i.e. if Mon is 1 and Wed is 4 and Fri is 16, then Mon | Wed | Fri is 21, which can be understood by code that knows how to check for [Flags]. Note that | can be used with more complex types, if custom operators are defined.

Upvotes: 5

Related Questions