0

I'm trying to call another class but get the error CS0176:

Member 'Player.MyMethod()' cannot be accessed with an instance reference; qualify it with a type name instead

What does the error message mean exactly? I thought this was how I created a C# class object/instance.

Code:

using System;

namespace Examples
{
    public class Player
    {
        public static void MyMethod()
        {
            Console.WriteLine("Hello!");
        }
    }

    public class Program
    {
        public static void Main()
        {
            var myObject = new Player();

            myObject.MyMethod();
        }
    }
}

Update

https://stackoverflow.com/a/1100023/9891285 had the answer, sorry! I removed the static-part of MyMethod().

halfer
  • 19,824
  • 17
  • 99
  • 186
jubibanna
  • 1,095
  • 9
  • 21

0 Answers0