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:
The function needs to be something like this:
However I'm not able to pass the function being non-static. Is there a way to achieve this or a better approach?
5 Replies
just have
(dt, added) => dt.AddDays(added)
, and then have Func<DateTime, double, DateTime>
actually
there isnt a function called AddDays DateTime.AddDays(Double) Method (System)
Returns a new DateTime that adds the specified number of days to the value of this instance.
not sure what i was looking at earlier
But yeah, to answer @Alex Frost 's question, since you need a DateTime reference to "add days" to, just do what Aaron suggested and add it to the func
Thank you guys, I'll try that. My understanding of C# basic concepts is lacking but will revise.