简体   繁体   English

为什么我的程序返回“CS0120:非静态字段、方法或属性‘Question3.primechec(BigInteger)’需要一个 object 引用”?

[英]why does my program return "CS0120: An object reference is required for the non-static field, method, or property 'Question3.primechec(BigInteger)'"?

im new to C# and ive been trying to solve project euler question number 3 and got the following error: i understand i need to decler a new BigInt before i use it, but i just cant figure out the syntax.我是 C# 的新手,我一直在尝试解决项目 euler 问题 3 并得到以下错误:我知道我需要在使用新的 BigInt 之前对其进行 decler,但我只是无法弄清楚语法。 would love to get some help!很想得到一些帮助!

using System;
using System.Numerics;
namespace primes
{
    class Question3
    {
       static void Main()
       {
        BigInteger Memash = 600851475143 ;
        for(BigInteger i = 100 ; i <= Memash ; i++)
            {
                if(primechec(i))
                    {
                        Console.Write("this number is prime: " + i);
                        if(Memash % i == 0)
                        {
                            Console.Write(i);
                        }
                    }
            }
       } 

       public bool primechec(BigInteger Naor)
       {
        for(int j = 2 ; j <= Naor ; j++)
        {
            if(Naor % j == 0)
            {
                return false;
            }
        }
        return true;
       }
    }
}

The problem is that your Main method is static , so it can't call instance methods in the same class.问题是您的Main方法是static ,因此它不能在同一个 class 中调用实例方法。 You need to declare primechec static as well, so you're calling a static method from a static method.您还需要声明primechec static,因此您从static static

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决程序中的 CS0120(非静态字段、方法或属性需要对象引用)? - How do I solve CS0120 in my program (An object reference is required for the non-static field, method, or property)? CS0120非静态字段,方法或属性需要对象引用 - CS0120 An object reference is required for the non-static field, method, or property CS0120 非静态字段、方法或属性“Form1.rtBox”需要 object 引用 - CS0120 An object reference is required for the non-static field, method, or property 'Form1.rtBox' CS0120非静态字段,方法或属性“ Group.Title”需要对象引用 - CS0120 An object reference is required for the non-static field, method, or property 'Group.Title' 错误 CS0120:非静态字段、方法或属性“CameraController.main”需要对象引用 - Error CS0120: An object reference is required for the non-static field, method, or property 'CameraController.main' CS0120:非静态字段,方法或属性&#39;_Default.txtEditValue&#39;需要对象引用 - CS0120: An object reference is required for the non-static field, method, or property '_Default.txtEditValue' 错误 CS0120:非静态字段、方法或属性“InventoryUI.newDiamondText”需要 object 引用 - Error CS0120: An object reference is required for the non-static field, method, or property 'InventoryUI.newDiamondText' 错误 CS0120:非静态字段、方法或属性“SetFaces.btnA”需要 object 引用 - error CS0120: An object reference is required for the non-static field, method, or property 'SetFaces.btnA' CS0120 非静态字段需要 object 参考 - CS0120 An object reference is required for the non-static field CS0120 非静态字段、方法或属性需要对象引用 - CS0120 Object reference is required for the non-static feild, method, or property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM