我有一个叫methods.cs
的类包含两种方法。如何使方法在同一个类中调用另一个方法?
例如method1
和method2
我要让method2
呼叫method1
代码澄清:
public static void Method1()
{
// Method1
}
public static void Method2()
{
// Method2
}
我要让Method2
电话Method1
。我怎样才能做到这一点?
我有一个叫methods.cs
的类包含两种方法。如何使方法在同一个类中调用另一个方法?
例如method1
和method2
我要让method2
呼叫method1
代码澄清:
public static void Method1()
{
// Method1
}
public static void Method2()
{
// Method2
}
我要让Method2
电话Method1
。我怎样才能做到这一点?
也许我失去了从你的问题的东西,但它应该是这样简单:
public static void Method1()
{
}
public static void Method2()
{
Method1();
}
public static void Method2()
{
// Method2
Method1();
}
这几乎是完全按照你刚才问同样的问题:
How to make method call another one in classes C#?
但是...
public class MyClass
{
public static void Method1()
{
// Method1
}
public static void Method2()
{
Method1();
}
}
很高兴见到你求助!为了在另一个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();
}
}
祝你好运,希望这有助于!
同意,你刚刚提出的两个问题强烈建议一个非常新的初学者,应该咨询初学者的内容。 – Gjeltema 2013-04-26 01:00:14
你在用什么C#书?您应该退还并要求退款。 – 2013-04-26 01:11:46