错误:“非静态字段、方法或属性…需要对象引用”。我正在用C#创建一个应用程序。它的功能是计算给定的是素数,以及是否相同的交换数也是素数。当我在VisualStudio中构建我的解决方案时,它说“非静态字段、方法或属性需要对象引用.”。我对“volteado”和“siprimo”方法有这个问题。问题在哪里,我如何解决?namespace ConsoleApplication1{
class Program
{
static void Main(string[] args)
{
Console.Write("Write a number: ");
long a= Convert.ToInt64(Console.ReadLine()); // a is the number given by the user
long av = volteado(a); // av is "a" but swapped
if (siprimo(a) == false && siprimo(av) == false)
Console.WriteLine("Both original and swapped numbers are prime.");
else
Console.WriteLine("One of the numbers isnt prime.");
Console.ReadLine();
}
private bool siprimo(long a)
{
// Evaluate if the received number is prime
bool sp = true;
for (long k = 2; k <= a / 2; k++)
if (a % k == 0) sp = false;
return sp;
}
private long volteado(long a)
{
// Swap the received number
long v = 0;
while (a > 0)
{
v = 10 * v + a % 10;
a /= 10;
}
return v;
}
}}
3 回答
catspeake
TA贡献1111条经验 获得超0个赞
Main()
static private long volteado(long a)
慕沐林林
TA贡献2016条经验 获得超9个赞
static
关于静态方法的更多信息
className.classMethod(arguments)rather than someInstanceVariable.classMethod(arguments)
Math.Sqrt(2) Math.Cos(Math.PI)
- 3 回答
- 0 关注
- 723 浏览
添加回答
举报
0/150
提交
取消