4 ms·
> implicit parameters (C# doesn't have an analog to these that I can think of) C# allows default values for parameters, but it's not quite the same. Example o
by jakevn 12y ago
> implicit parameters (C# doesn't have an analog to these that I can think of)
C# allows default values for parameters, but it's not quite the same.
Example of C# default value for parameter:
static void Addition(int a, int b = 42)
{
Console.WriteLine(a + b);
}
Addition(4); // Prints 46
Addition(4, 5); // Prints 9
In Scala, the default (implicit) value has more complex rules.
Like C#, implicit parameters must come after non-implicit parameters (if any).
Unlike C#, the implicit value does not need to be defined in the signature. Also unlike C#, if you provide the value for one implicit parameter, you must provide the value for all implicit parameters.
- dragonwriter 12y ago> C# allows default values for parameters, but it's not quite the same. Right. Scala has C#-style default parameters as well, implicit parameters are a different (though very loosely related) thing.