1

我需要返回两个变量类型的三个值,所以我决定使用refout参数,但是我在实现它们时遇到了麻烦。我不断收到这些“方法'GETValues'没有重载需要0个参数”错误。我究竟做错了什么?

public static double GETValues(out string empName, out double dblSal, out double dblMonthSales)
    {
        string salaryStr,
               monthlySales;

        Console.Write("Enter employee's name (enter nothing to quit) : ");
        empName = Console.ReadLine();
        Console.Write("Enter Annual Salary (0 for pure commission): ");
        salaryStr = Console.ReadLine();
        dblMonthSales = Double.Parse(salaryStr);
        Console.Write("Enter monthly sales: ");
        monthlySales = Console.ReadLine();
        dblSal = Double.Parse(monthlySales);

        return dblMonthSales;
        return dblSal;
4

1 回答 1

0

你不做多次退货。您设置 out 变量的值(您已经这样做了)。您可以返回一个双精度 - 但在您的代码段中,您试图返回您已经在“out”参数中设置的两个值。

您的调用代码应类似于:

string empname = "default";
double salary = 0.0;
double monthSales = 0.0;
double whatIsThis = GETValues(empname, salary, monthsales);
// empname, salary and monthSales should now be set correctly.
// not sure what you intend for the return val.
于 2012-10-22T22:28:39.447 回答