The best overloaded method match for … has some invalid arguments C#
public static void masodmegold(double a,double b,double c)
{
double x0, x1, x2;
double gyokalatt = b * b - 4 * a * c;
if (gyokalatt > 0)
{
x1 = ( -b + Math.Sqrt(gyokalatt)) / (2 * a);
x2 = ( -b - Math.Sqrt(gyokalatt)) / (2 * a);
Console.WriteLine("két gyök: ", x1, x2);
}
else if (gyokalatt == 0)
{
x0 = ( -b / (2 * a));
Console.WriteLine("egy gyök: ", x0);
}
else
{
Console.WriteLine("blabla!");
}
}
static void Main(string[] args)
{
Console.WriteLine(masodmegold(1,-4,3));
Console.ReadKey();
}
And there are two errors
Error 1
The best overloaded method match for 'System.Console.WriteLine(string, params object[])' has some invalid arguments
Error 2
Argument 1: cannot convert from 'void' to 'string'
Your masodmegold
method returns void,See public static void masodmegold
either you need to change return type void to something
public static string masodmegold(double a,double b,double c)
{
//Your code here
//change Console.WriteLine("két gyök: ", x1, x2); to Cnsole.WriteLine("két gyök: "+ x1+""+ x2);
return "Some string you want to print"
}
Or in main you can call it like directly without changing its return type,
masodmegold(1,-4,3)
Console.writeline()
expects a parameter, you are passing masodmegold(1,-4,3)
with return type as void, which is equivalent to Console.writeline(void)
. So you getting the error.
Here is the line causing compilation errors:
Console.WriteLine(masodmegold(1,-4,3));
It shoult be just
masodmegold(1,-4,3);
Your masodmegold
method has type void
so it doesn't returns anythig - thus you have nothing to pass to ConsoleWriteLine
after this method execution.
You should just call the method itself, without passing it as argument to Console.WriteLine
Error 1 The way you build your strings are wrong, try something like this:
Console.WriteLine("két gyök: " + x1 + " " + x2);
You could also look into the string.Format method.
Error 2 Main method:
static void Main(string[] args)
{
masodmegold(1,-4,3);
Console.ReadKey();
}
链接地址: http://www.djcxy.com/p/89840.html
上一篇: 尝试将Web服务连接到数据库时出错