In C #, you can define default options as described here . I played with tuples and C # 7 (using LinqPad beta ) as follows:
void Main()
{
var result=AddTuples((1,2), (3,4));
Console.WriteLine($"Result is: {result}");
}
(int x, int y) AddTuples((int x, int y) a, (int x, int y) b)
{
return (a.x+b.x, a.y+b.y);
}
This works fine, it shows the sum of a and b:
Result: (4, 6)
Now I tried to change AddTuples
to have default options, but for some reason I could not figure out how to do this. What I tried is something like:
(int x, int y) AddTuples2((int x, int y) a = (0,0), (int x, int y) b=(0,0))
{
return (a.x + b.x, a.y + b.y);
}
But I get an error message:
CS1736 The default parameter value for 'a' must be a compile-time constant
CS1736 The default parameter value for 'b' must be a compile time constant
What am I doing wrong?
Update
, . : , 3 :
. 1., 2. 4. , 3. , default
.