|
|
The answer to the first question of what is a delegate is :- A delegate is a type-safe function pointer. It allows you to combine two functions, either in the same module ( or class ) or in separate modules.
In this guide, we're only going to concentrate on single methods. Have a look at the following example.
Imports System
Module Main
Private Delegate Sub dele()
Sub Main()
Dim a as dele, b as dele, z as dele
a = address one
b = address two
z = system.delegate.combine(a,b)
z()
end Sub
sub a()
console.writeline "A"
end sub
sub b()
Console.write "B"
end Sub
End Module
The line starting Private is a declaration more than anything else. There should be no code in the sub and no end sub. You can use function instead of sub. If you intend to use parameters, then both
"delegated" subs must have the same number and types of parameters. In the below example, we use functions instead of subs. The result printed to the screen is the return value of the second function call.
Imports System
Module Main
Private Delegate function dele(ab as integer,bb as integer)
Sub Main()
Dim a as dele, b as dele, z as dele
a = addressof one
b = addressof two
z = system.delegate.combine(a,b)
console.writeline(z(5,5))
end Sub
function One(ab as integer, bb as integer)
return ab+bb
end function
function Two(ab as integer, bb as integer)
return ab*bb
end function
End Module
Make a comment*Comments are the views of individuals, they may or may not be correct. All comments are reviewed and accepted or rejected. If you give an email address, you will be sent an email when someone makes a comment on this page.* | Only name and Code is compulsory. |
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
|