錯誤:“非靜態(tài)字段、方法或屬性…需要對象引用”。我正在用C#創(chuàng)建一個應用程序。它的功能是計算給定的是素數(shù),以及是否相同的交換數(shù)也是素數(shù)。當我在VisualStudio中構建我的解決方案時,它說“非靜態(tài)字段、方法或屬性需要對象引用.”。我對“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
關于靜態(tài)方法的更多信息
className.classMethod(arguments)rather than someInstanceVariable.classMethod(arguments)
Math.Sqrt(2) Math.Cos(Math.PI)
- 3 回答
- 0 關注
- 791 瀏覽
添加回答
舉報
0/150
提交
取消