using System;
using System.Collections.Generic;
using System.Text;
namespace 输出参数求解一元二次方程
{
class Program
{
public static void Root(int a, int b, int c, out double root1, out double root2)
{
double d = b * b - 4 * a * c;
double Sqrt = Math.Sqrt(d);
if (d > 0)
{
root1 = (-b + Sqrt) /( 2 * a);
root2 = (-b - Sqrt) / (2 * a);
}
else if (d == 0)
{
root1 = root2 = -b / (2 * a);
}
else
Console.WriteLine("此方程无根");
}
static void Main(string[] args)
{
int a = 5, b = 6, c = 1;
double root1, root2;
Root (a, b, c, out root1, out root2);
Console.WriteLine("root1 :{0},root2:{1}", root1, root2);
}
}
}
错误提示为控制离开方法之前必须对out参数root1.root2赋值。
我已经赋值了啊,为什么还会提示要对输出参数赋值的错误?