Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing methods from another class in C#

Tags:

c#

class

I have a number of classes in a Classes file, and I want them all to be able to access the same, global method to save duplicating code. Problem is, I can't seem to access a method from another class in my file - any ideas?

So my class1.cs layout is similar to this:

public class Job1
{
    public Job1()
    {

    }
}

public class Methods
{
    public static void Method1()
    {
        //Want to access method here from Job1 
    }
}
like image 425
Chris Avatar asked Nov 03 '10 19:11

Chris


1 Answers

You'll need to specify the class they are in. Like this:

public Job1()
{
  Methods.Method1()
}

If the class Job1 is in a different namespace from Methods then you'll need to either add a using clause, or specify the the namespace when calling the method. Name.Space.Methods.Method1()

like image 92
CodesInChaos Avatar answered Oct 20 '22 17:10

CodesInChaos