time and space

time and space

  • 1.6k
  • 31
  • 55.8k

How to assign TimeSpan with a default value when using it as an argument?

Jul 25 2011 7:35 AM
This does not work:

public void DoStuff(TimeSpan interval = TimeSpan.FromSeconds(5))

The compiler error is: "Error 1 Default parameter value for 'interval' must be a compile-time constant".

I have tried making a const field in the class but still no luck.

Answers (13)