default function parameters in C#
Is there a way to have d开发者_Go百科efault function parameters in C# like we have in C++??
eg:
foo(int i = 10, int j = 20) {}
Named and optional parameters are new in C# 4.0.
Yes, default parameters are in C# 4.0.
You can do this only in C# 4.0.
if you don't have C# 4 you can define your method twice, like this:
public int MySillyMethod(int a)
{
return MySillyMethod(a, 1);
}
public int MySillyMethod(int a, int b)
{
return a*b;
}
精彩评论