开发者

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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜