gpt4 book ai didi

c# - C# 中的 2 个参数未编译

转载 作者:太空宇宙 更新时间:2023-11-03 17:18:06 24 4
gpt4 key购买 nike

我正在尝试这样做:

public void CustomMethod(params int[] number,params string[] names)
{
...
}

如果我删除其中一个,没有问题,知道为什么我不能这样做吗?

我试过在两者中间放置一个普通参数。

最佳答案

只有最后一个参数可以有params。查看documentation .

No additional parameters are permitted after the params keyword in a method declaration, and only one params keyword is permitted in a method declaration.

原因是允许多个参数会产生歧义。例如,这意味着什么?

public void CustomMethod(params int[] foo, params int[] bar)
{
...
}

// ...

CustomMethod(1, 2);

关于c# - C# 中的 2 个参数未编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9801882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com