Home > Blockchain >  Member can't be accessed by reference by instances. Error suggests to Qualify it with a type na
Member can't be accessed by reference by instances. Error suggests to Qualify it with a type na

Time:05-15

I got an issue With OOP with C#.

It says that "Member "" can't be accessed with instance reference. Qualify it with a type name instead."

Error: Click Here

Code for the reference:



class Car
    {
        
        public static String Model;
        public static int Year;
        public static String Brand;

        public Car(string Name, string Model, int Year, String Brand)
        {
            
            this.Model = Model;
            this.Year = Year;
            this.Brand = Brand;
        }

        public static void Drive()
        {
            Console.WriteLine($"Your car - {Car.Brand} {Car.Model} made in {Car.Year} can be driven now.");
        }
    }


I checked this website:

member cannot be accessed with an instance reference; qualify it with a type name instead

But still not working.

CodePudding user response:

Remove the word static everywhere. Apart from in the case of static void Main, which is required to get your program going (but actually might not be visible any more if you're using very modern C#) do not use the word static at all when you're learning OOP; it shoots you in the foot because it essentially "turns off" the object orientation part of "object orientated programming"

  • Related