当 C# 函数中的命名参数丢失时,编译器仅打印丢失的参数数量,而不是打印函数中每个丢失参数的名称:
prog.cs(10,27): error CS1501: No overload for method `createPrism' takes `2' arguments`.
但是,出于调试目的,通常需要获取函数调用中缺少的参数的名称,尤其是对于带有许多参数的函数。是否可以在 C# 函数调用中打印缺少的参数?
using System;
public class Test{
public static int createPrism(int width, int height, int length, int red, int green, int blue, int alpha){
//This function should print the names of the missing parameters
//to the error console if any of its parameters are missing.
return length*width*height;
}
static void Main(){
Console.WriteLine(getVolume(length: 3, width: 3));
//I haven't figured out how to obtain the names of the missing parameters in this function call.
}
}