Created
March 20, 2010 03:11
-
-
Save rtipton/338449 to your computer and use it in GitHub Desktop.
C#/VBNet -- Simple Delegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace DelegateTest | |
{ | |
public delegate void TestDelegate(string message); | |
class Program | |
{ | |
public static void Display(string message) | |
{ | |
Console.WriteLine(""); | |
Console.WriteLine("The string entered is : " + message); | |
} | |
static void Main(string[] args) | |
{ | |
//-- Instantiate the delegate | |
TestDelegate t = new TestDelegate(Display); | |
//-- Input some text | |
Console.WriteLine("Please enter a string:"); | |
string message = Console.ReadLine(); | |
//-- Invoke the delegate | |
t(message); | |
Console.ReadLine(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Namespace DelegateTest | |
Public Delegate Sub TestDelegate(ByVal message As String) | |
Class Program | |
Public Shared Sub Display(ByVal message As String) | |
Console.WriteLine("") | |
Console.WriteLine("The string entered is : " + message) | |
End Sub | |
Shared Sub Main(ByVal args As String()) | |
'-- Instantiate the delegate | |
Dim t As New TestDelegate(AddressOf Display) | |
'-- Input some text | |
Console.WriteLine("Please enter a string:") | |
Dim message As String = Console.ReadLine() | |
'-- Invoke the delegate | |
t(message) | |
Console.ReadLine() | |
End Sub | |
End Class | |
End Namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment