此方法不使用错误编译“Index1的默认参数必须是编译时常量。我正在传递一个int3;为什么会发生这种情况?我如何解决这个问题?
public void C_Loader(int[] Index1 = new int[3] {4,4,4}, int[] Index2 = new int[3] {8,8,8}, int[] Index3 = new int[3] {10,10,10})
发布于 2022-01-17 11:52:03
来自MSDN
“默认值必须为下列之一:
不变的表达方式;
一个新ValType()表单的表达式,其中ValType是一个值类型,例如枚举或结构;
表单默认值( ValType )的表达式,其中ValType是值类型。
您创建的数组不遵循上述任何一个规则
尝尝这个
public void C_Loader(int[] Index1=null, int[] Index2=null , int[] Index3=null)
{
if(Index1 ==null) Index1= new int[] {4,4,4};
if (Index2 == null) Index2 = new int[] { 8, 8, 8 };
if (Index3 == null) Index3 = new int[] { 10, 10, 10 };
.... your code
}
https://stackoverflow.com/questions/70740767
复制相似问题