Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:24:48+00:00 2026-06-17T23:24:48+00:00

Possible Duplicate: An object reference is required for the non-static field, method, or property

  • 0

Possible Duplicate:
“An object reference is required for the non-static field, method, or property”

I’m trying to get to grips with programming, and have just started learning C#, so first off, apologies for probably asking a really basic question which may have been answered hundreds of times. However, I can’t seem to understand the answers and relate the answers out there to what I am trying to do.

I keep getting “An object reference is required for the non-static field, method or property ‘FirstConsoleApplication.Program.function(string)'”

Can anyone point out where I’m losing this? I’m using visual studio 2008.

namespace FirstConsoleApplication
{
   class Program
   {   
       static void Main(string[] args)
       {
          Console.WriteLine("Type in an integer vale");
          string num;
          num = Console.ReadLine();
          string result1 = function1(num);
          Console.WriteLine(result1);
          Console.ReadLine();
       }

       string function1(string x)
       {
          Int32 isnumber = 0;
          bool canConvert = Int32.TryParse(x, out isnumber);
          string returnValue;
          if (canConvert == true)
          {
             int val3 = Int32.Parse(x);

             switch (val3)
             {
                case 50:
                    returnValue = "yep its 50";
                    break;
                case 51:
                    returnValue = "hmmm.... its 51... what are you gonna do about that??";
                    break;
                case 52:
                    returnValue = "lets not get sloppy now...";
                    break;
                default:
                    returnValue = "nope, its definately something else";
                    break;
            };

        }
        else
        {
            returnValue = "Thats not a number";
        };
        return returnValue;
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:24:49+00:00Added an answer on June 17, 2026 at 11:24 pm

    Complete code

    namespace FirstConsoleApplication
    {
    class Program
        {   
            static void Main(string[] args)
            {
    
                Console.WriteLine("Type in an integer vale");
                string num;
                num = Console.ReadLine();
                string result1 = function1(num);
                Console.WriteLine(result1);
                Console.ReadLine();
            }
    
            static string function1(string x)
            {
                Int32 isnumber = 0;
                bool canConvert = Int32.TryParse(x, out isnumber);
                string returnValue;
                if (canConvert == true)
                {
                    int val3 = Int32.Parse(x);
    
                    switch (val3)
                    {
                        case 50:
                            returnValue = "yep its 50";
                            break;
                        case 51:
                            returnValue = "hmmm.... its 51... what are you gonna do about that??";
                            break;
                        case 52:
                            returnValue = "lets not get sloppy now...";
                            break;
                        default:
                            returnValue = "nope, its definately something else";
                            break;
                    };
    
                }
                else
                {
                    returnValue = "Thats not a number";
                };
                return returnValue;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: An object reference is required for the non-static field, method, or property
Possible Duplicate: javascript object, access variable property name? I'm trying to call a method
Possible Duplicate: How do I reference a javascript object property with a hyphen in
Possible Duplicate: get methodinfo from a method reference C# This is most likely something
Possible Duplicate: How come a non-const reference cannot bind to a temporary object? This
Possible Duplicate: Object reference not set to an instance of an object errors when
Possible Duplicate: JavaScript losing “this” object reference with private/public properties Why does the second
Possible Duplicate: Comparing object properties in c# Let's say I have a POCO: public
Possible Duplicate: Python: Get object by id Typically when you see the string representation
Possible Duplicate: Why do this Ruby object have two to_s and inspect methods that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.