0

有没有办法在另一个函数中调用函数,例如:

call functionname()

但这只能在子内调用,是否有一个回合?,我尝试过使用 GOTO,但即使它也应该在同一个子或函数内。

4

4 回答 4

2

Well you can do this

public void myfunc()
{
}

public void callerOfMyFunc()
{
    myFunc();
}

I think you might want to read up a little about Methods (C# Programming Guide)

A method is a code block that contains a series of statements. A program causes the statements to be executed by calling the method and specifying any required method arguments. In C#, every executed instruction is performed in the context of a method. The Main method is the entry point for every C# application and it is called by the common language runtime (CLR) when the program is started.

Even for VB you can look at Sub Procedures (Visual Basic)

A Sub procedure is a series of Visual Basic statements enclosed by the Sub and End Sub statements. The Sub procedure performs a task and then returns control to the calling code, but it does not return a value to the calling code.

Each time the procedure is called, its statements are executed, starting with the first executable statement after the Sub statement and ending with the first End Sub, Exit Sub, or Return statement encountered.

You can define a Sub procedure in modules, classes, and structures. By default, it is Public, which means you can call it from anywhere in your application that has access to the module, class, or structure in which you defined it. The term, method, describes a Sub or Function procedure that is accessed from outside its defining module, class, or structure. For more information, see Procedures in Visual Basic.

A Sub procedure can take arguments, such as constants, variables, or expressions, which are passed to it by the calling code.

于 2013-08-09T09:21:02.743 回答
1
Public Sub DoSomething
    OtherFunction()
End Sub

Public Sub OtherFunction()
    'Do something here
End Sub
于 2013-08-09T09:25:03.157 回答
1

How about this?

Function MethodOne() As Boolean
    Dim result As Boolean = False

    ' Do something 

    Return result
End Function

Function MethodTwo() As Boolean
    ' Call Method One
    Dim res As Boolean = MethodOne()

    Return res
End Function
于 2013-08-09T09:28:09.017 回答
0
Function MethodOne() As Boolean
    Dim result As Boolean = False

    ' Do something 

    Return result
End Function

Function MethodTwo() As Boolean
    ' Call Method One
    Dim res As Boolean = MethodOne()
End Function
于 2014-10-24T09:02:51.500 回答