Antonio
Antonio

Reputation: 23

Compiler Error CS0117

I have two Projects in one Solution and I want to call a Method from Project1 in Project 2. I already refered the Namespace of Project1 in Project2. The Method from Project1 looks like this:

public void pauseCapturing(bool checkPause)
    {
        if (checkPause)
        {
            backgroundThread.Suspend();
        }
        else
        {
            backgroundThread.Resume();
        }
    }

In Project2 I call that Method like that:

private void buttonPause_Click(object sender, EventArgs e)
    {
        buttonPause.Enabled = false;

        NamespaceProject1.Class.pauseCapturing(true);
    }

When I try to run the code i get the following error:

Error 1 'NamespaceProject1.Class' does not contain a definition for 'pauseCapturing'

I didn't really found a helpful answer to solve my problem.

Upvotes: 2

Views: 19014

Answers (1)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

you need to create an instance for accessing the methods declared in another class.

in your case you have created method pauseCapturing() as an non-static method hence need an instance to call it.

Note : if the method is declared as a static then you can use class name to access it.

Try This:

NamespaceProject1.Class obj=new NamespaceProject1.Class();
obj.pauseCapturing(true);

Upvotes: 3

Related Questions