Non-static method requires a target

C

csharpula csharp

Non-static method requires a target appeares when I am trying to activte
nunit (test). Any clue?
Thank you!
 
B

Barry Kelly

csharpula said:
Non-static method requires a target appeares when I am trying to activte
nunit (test). Any clue?
Thank you!

You are calling a static method on an instance. For example, if you have
the following code:

---8<---
class C {
public static void F() { }
}

// ...
C c = new C();
c.F();
--->8---

.... it will cause the same error. You need to use the type name instead
of the instance:

C.F();

-- Barry
 
B

Bruce Wood

Barry said:
You are calling a static method on an instance. For example, if you have
the following code:

---8<---
class C {
public static void F() { }
}

// ...
C c = new C();
c.F();
--->8---

... it will cause the same error. You need to use the type name instead
of the instance:

C.F();

-- Barry

I may be missing something, but doesn't "non-static method requires a
target" mean the inverse: that the method is an instance method
("non-static method") but the caller is trying to call it without
specifying an instance?
 
B

Barry Kelly

Bruce said:
I may be missing something, but doesn't "non-static method requires a
target" mean the inverse: that the method is an instance method
("non-static method") but the caller is trying to call it without
specifying an instance?

No, I'm sure I'm missing something; it's roughly the right area though
:)

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top