Possible Duplicate:
C# 4.0: Can I use a TimeSpan as an optional parameter with a default value?
Ok I know how to create default parameters for some of the variables. for example I can create default parameters as:
public void someMethod(int x = 1, double y = 2)
{
//....
}
ok but let's say that my method requires an object of type TimeSpan. when I try:
public void someMethod(TimeSpan t = TimeSpan.FromSeconds(3)){
}
I get the error:
Default parameter value for 't' must be a compile time constant
as a result I tried creating a constant of type TimeSpan as:
private const TimeSpan defaultVal = TimeSpan.FromSeconds(3);
public void someMethod(TimeSpan t = defaultVal)
{
}
and this too gives me an error. How can I solve this?