2013-04-26 111 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(); 
    } 
} 

祝你好運,希望這有助於!

相關問題