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

11,583

I got the answer. static method name should be different.

public static string getMem()
        {
            return MemberFactory.Current.getMember();
}

This will fix the issue. Thank god.

Share:
11,583

Related videos on Youtube

Anna.P
Author by

Anna.P

I am a .net resource having 7+ years of exp

Updated on June 04, 2022

Comments

  • Anna.P
    Anna.P almost 2 years

    I have abstract class

    public abstract class MemFactory 
    {
        public abstract bool test();
    
        public virtual string getMember()
        {
            string validMember = "test"; 
            return validMember;
        }
    }
    

    I have inherited the same in another child class

    public class MemberFactory : MemFactory
    {
     private static readonly MemberFactory instance = new MemberFactory();
    
     static MemberFactory() { }
    
      public static MemberFactory Current
      {
            get { return instance;}
      }
    
     public static string getMember()
     {
         return MemberFactory.Current.getMember();
     }
    }
    

    When i am accessing the base class method its giving me

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

    Can anyone help?