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 7848199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:07:05+00:00 2026-06-02T18:07:05+00:00

When I’m trying some code to learn about passing a reference of an object

  • 0

When I’m trying some code to learn about passing a reference of an object to a method, I get an error when I try to remove the static in the methods head. The error message says: An object reference is required for non-static field, method or property…… But isn’t there a reference in the parameter already? I have seen code that don’t use static, so why does this not work? I know that static is used when method is used from classes that isn’t objects. Some explanation is appreciated to understand. Thanks!

    // Method
    internal static string ChangeName(Box obj)
    {
        return obj.BoxName;
    }

EDIT: I added the whole code. Is the problem that I’m calling from inside the main method that is static?

class Program
{
    static void Main(string[] args)
    {

        Box box1, box2;
        box1 = new Box("Nick","R90",1);
        box2 = new Box("Hanna","B27",2);

        Console.WriteLine(ChangeName(box2));
        Console.Read();

    }

    // Methods
    private static string ChangeName(Box obj)
    {
        return obj.BoxName;
    }
}
  • 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-02T18:07:07+00:00Added an answer on June 2, 2026 at 6:07 pm

    A static method is called like this:

    MyClass.Method(arg);
    

    An instance method is called like this:

    MyClass myInstance = new MyClass();
    myInstance.Method(arg);
    

    The two are not compatible.

    If you want to change the method signature, you also need to change every place where the method is called.

    EDIT: You are using the unqualified call. Here are the rules for using an unqualified call.

    • A static method can call a static method.
    • A static method cannot call an instance method. (This is your problem.)
    • An instance method can call a static method.
    • An instance method can call an instance method.

    This method should really be implemented as an instance method in the Box class. You would then say:

    Console.WriteLine(box2.ChangeName());
    

    If you don’t have access to the Box code, and then you could either write an extension method, or keep the method static as per your example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.