How to do it in VB?

td.Triggers.Add(New DailyTrigger{DaysInterval = 2})

^^^ is C # .NET code.

How to do it in VB.NET? I am particularly confused by some of the curly shapes, because VB.NET does not seem to like it.

+3
source share
2 answers
td.Triggers.Add(New DailyTrigger() With { _
    Key .DaysInterval = 2 })
+3
source

To explain curly braces, this is just a shortcut to the following:

DailyTrigger dt = new DailyTrigger();
dt.DaysInterval = 2;
td.Triggers.Add(dt);

So the equivalent in VB will be simple:

Dim dt As DailyTrigger = new DailyTrigger()
dt.DaysInterval = 2
td.Triggers.Add(dt)

Or use a similar Withshortcut:

td.Triggers.Add(New DailyTrigger() With { .DaysInterval = 2 })

But this shortcut syntax was not added to VB.NET until a later version (part of LINQ, I believe), so if you are not using the latest version of .NET, this may not work.

+3
source

All Articles