我搜索了一些 C# 默认字符串参数的例子,发现是这样的。
字符串异常 = "约翰"
我需要为字符串 [] 设置默认值,但您还没有找到如何将字符串数组设置为 C# 方法的默认值。
static int startapp(string Source, string Destination, string[] Exceptions = { "John", "Paul", "Mary" })
{
//do something
}
抱歉,这必须是评论,但我没有足够的声誉来添加评论。您可能正在寻找的是这个答案
optional array Parameter in C# [duplicate]
它说(来自文档)
A default value must be one of the following types of expressions:
a constant expression;
an expression of the form new ValType(), where ValType is a value type, such as an enum or a struct;
an expression of the form default(ValType), where ValType is a value type.