2013-04-26 94 views
0

我有一个叫methods.cs的类包含两种方法。如何使方法在同一个类中调用另一个方法?

例如method1method2

我要让method2呼叫method1

代码澄清:

public static void Method1() 
{ 
// Method1 
} 

public static void Method2() 
{ 
// Method2 
} 

我要让Method2电话Method1。我怎样才能做到这一点?

+3

同意,你刚刚提出的两个问题强烈建议一个非常新的初学者,应该咨询初学者的内容。 – Gjeltema 2013-04-26 01:00:14

+1

你在用什么C#书?您应该退还并要求退款。 – 2013-04-26 01:11:46

回答

4

也许我失去了从你的问题的东西,但它应该是这样简单:

public static void Method1() 
{ 

} 

public static void Method2() 
{ 
    Method1(); 
} 
0
public static void Method2() 
{ 
// Method2 
    Method1(); 
} 
5

很高兴见到你求助!为了在另一个Method中调用Method,它包含在同一个Class中非常简单。只是叫它的名字! Here is a nice little tutorial on Methods和我的例子在下面!

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(); 
    } 
} 

祝你好运,希望这有助于!

相关问题