Delegates Sample: Demonstrates Custom Delegates in a Managed Application
The Delegates sample illustrates the DelegateConsole class. It implements two uses of a delegate (single-cast and multicast) using the __delegate keyword. For more information on delegates, see Delegates in Managed Extensions for C++.
The sample also demonstrates interoperability between a Managed Extensions for C++ application and a C# DLL (
csdel). The C# DLL implements a basic C# class (
CDel) with a custom method.
Building and Running the Sample
To build and run Delegates using Visual Studio
- In the Visual Studio IDE, load the solution file Delegates.sln.
- In Solution Explorer, right-click the Delegates solution.
- On the shortcut menu, click Build Solution.
- On the Debug menu, click Start.
When the sample is built and run, single-cast and multicast delegates are created and invoked:
A single-cast delegate is created and then the bound method is invoked. The confirmation is a printed string with the value passed by the single-cast delegate.
Before creating the multicast delegate, the C# class (
CDel) is first instantiated. The delegate is then bound to both the C# and managed class methods and invoked. The confirmation is a printed string with the value passed by the multicast delegate.