相关疑难解决方法(0)

C#4.0,可选参数和参数不能一起使用

如何创建一个具有可选参数和参数的方法?

static void Main(string[] args)
{

    TestOptional("A",C: "D", "E");//this will not build
    TestOptional("A",C: "D"); //this does work , but i can only set 1 param
    Console.ReadLine();
}

public static void TestOptional(string A, int B = 0, params string[] C)
{
    Console.WriteLine(A);
    Console.WriteLine(B);
    Console.WriteLine(C.Count());
}   
Run Code Online (Sandbox Code Playgroud)

.net c# optional-parameters params c#-4.0

60
推荐指数
3
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

c#-4.0 ×1

optional-parameters ×1

params ×1