9

I have a class called methods.cs contains two methods.

For example method1 and method2

I want to make method2 call method1

Code clarification:

public static void Method1()
{
// Method1
}

public static void Method2()
{
// Method2
}

I want to make Method2 call Method1. How can I achieve that?

Irshad
  • 3,071
  • 5
  • 30
  • 51
Mina Hafzalla
  • 2,681
  • 9
  • 30
  • 44

4 Answers4

14

Great to see you seeking help! In order to call Method in another Method that is contained in the same Class is pretty simple. Just call it by its name! Here is a nice little tutorial on Methods and my example is below!

public class ClassName
{
    // Method definition to call in another Method
    public void MethodToCall()
    {
        // Add what you want to be performed here
    }

    // Method definition performing a Call to another Method
    public void MethodCalling()
    {
        // Method being called. Do this by using its Method Name
        // be sure to not forget the semicolon! :) 
        MethodToCall();
    }
}

Best of luck to you and hope this helps!

5

Maybe I'm missing something from your question, but it should be as simple as this:

public static void Method1()
{

}

public static void Method2()
{
    Method1();
}
Chris Sinclair
  • 22,858
  • 3
  • 52
  • 93
3

This is almost exactly the same question as you just asked:

How to make method call another one in classes C#?

But...

public class MyClass
{
   public static void Method1()
    {
        // Method1
    }

    public static void Method2()
    {
        Method1();
    }
}   
Community
  • 1
  • 1
Gjeltema
  • 4,122
  • 2
  • 24
  • 31
0
public static void Method2()
{
// Method2
    Method1();
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397