© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
38 replies
Nor

CS0120 - Object refrence required for the non static field, method, or property "object.Equals(obj)"

Hello! I am a self learning programmer beginning with c#.
I am trying to code a randomized Math Quiz in a Console app, and i am currently trying to validate the user input and then have it print "Correct" or "False" depending on the answer.
Now, im not sure as how to approach this, but i have a general idea of the code and i coded it, its just that i have no idea how to make it check whether the answer was correct, and it gives me the aforementioned error.

Heres my code:
// START HERE
            Console.WriteLine("Welcome to this Math Quiz!");
            Console.WriteLine("This is your first question");

            // RNG
            Random rnd = new Random();
            float random1 = rnd.Next(-100, 100);
            float random2 = rnd.Next(-100, 100);
        
            Console.WriteLine("{0} + {1}?", random1, random2);
            
            // Checks if answer is correct

            float answer = random1 + random2;
            Convert.ToBoolean(answer);

            if (Console.ReadLine(Equals(answer)))
            {
                Console.WriteLine("Correct!");
            }
            else
            {
                Console.WriteLine("False!");
            }
// START HERE
            Console.WriteLine("Welcome to this Math Quiz!");
            Console.WriteLine("This is your first question");

            // RNG
            Random rnd = new Random();
            float random1 = rnd.Next(-100, 100);
            float random2 = rnd.Next(-100, 100);
        
            Console.WriteLine("{0} + {1}?", random1, random2);
            
            // Checks if answer is correct

            float answer = random1 + random2;
            Convert.ToBoolean(answer);

            if (Console.ReadLine(Equals(answer)))
            {
                Console.WriteLine("Correct!");
            }
            else
            {
                Console.WriteLine("False!");
            }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

static or object
C#CC# / help
4y ago
❔ A field initializer cannot reference the nonstatic field, method, or property
C#CC# / help
4y ago
Understanding Equals() method
C#CC# / help
4mo ago