© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
7 replies
Alex Frost

Pass DateTime.Add function as parameter

I have a switch statement that will call a generation function so I don't have to loop for every scenario:
switch (E.RepMode)
{
    case "daily":
        repeats.Add(GenerateRepeats(entry.DateStart, entry.DateEnd, 1, DateTime.AddDays));
        break;
    case "weekly":
        break;
    case "monthly":
        break;
    case "yearly":
        break;
}
switch (E.RepMode)
{
    case "daily":
        repeats.Add(GenerateRepeats(entry.DateStart, entry.DateEnd, 1, DateTime.AddDays));
        break;
    case "weekly":
        break;
    case "monthly":
        break;
    case "yearly":
        break;
}

The function needs to be something like this:
public List<EntryRepeat> GenerateRepeats(DateTime start, DateTime end, int interval, Func<double, DateTime> f)
{
    do
    {

    }
    while (true);
}
public List<EntryRepeat> GenerateRepeats(DateTime start, DateTime end, int interval, Func<double, DateTime> f)
{
    do
    {

    }
    while (true);
}

However I'm not able to pass the function being non-static. Is there a way to achieve this or a better approach?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Pass variable type as class parameter
C#CC# / help
3y ago
✅ Pass status as parameter in controller
C#CC# / help
3y ago
❔ function overloading with Type as parameter.
C#CC# / help
3y ago
❔ beginner - is it possible to pass a prop to a function as parameter?
C#CC# / help
4y ago