2

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?

Oded
  • 489,969
  • 99
  • 883
  • 1,009
Anna.P
  • 903
  • 1
  • 6
  • 17

1 Answers1

1

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.

Anna.P
  • 903
  • 1
  • 6
  • 17
  • 5
    Now that your issue is fixed, you may want to delete the question: it's a rather localized problem, it's unlikely to help others, and you already found your answer. – Sergey Kalinichenko Jan 27 '13 at 12:55
  • 1
    Your base class already has a `getMember()` method. It's an instance method. Your derived class introduces a **new** method also called `getMember()`, parameter list is the same (zero parameters). Therefore the first `getMember()` method is **hidden** by the new one. This is true even if one method is non-static (instance method) and the other is `static`. Never introduce new members that hide old members with the same name, if you can avoid it. Note: The first `getMember` method was virtual. They intended classes to `override` it. That gives another implementation to the **same** method. – Jeppe Stig Nielsen Jan 27 '13 at 13:54
  • 1
    @dasblinkenlight Just came here 2 years later with same issue, glad he never deleted this question. – Thompson Oct 27 '15 at 15:54
  • @Thompson There's lots of other answers on this site covering the "static member cannot be accessed with an instance reference" topic, so deleting would have made no difference to you :) – Sergey Kalinichenko Oct 27 '15 at 16:01