using namespace System;
namespace Delegate
{
ref class Hoge
{
public :
event EventHandler^ Piyo;
Hoge( ) { }
void Raise( ) { Piyo( nullptr, EventArgs:: Empty ) ; }
} ;
ref class Program
{
static void Main( )
{
Hoge^ hoge = gcnew Hoge;
hoge- > Piyo + = gcnew EventHandler( & Hoge1) ;
hoge- > Piyo + = gcnew EventHandler( & Hoge2) ;
hoge- > Piyo + = gcnew EventHandler( & Hoge3) ;
hoge- > Raise( ) ;
auto mcd = ( MulticastDelegate^ ) hoge- > Piyo;
auto list = mcd- > GetInvocationList( ) ;
}
static void Hoge1( Object^ sender, EventArgs^ e) { System:: Diagnostics :: Debug :: Print ( "Hope1" ) ; }
static void Hoge2( Object^ sender, EventArgs^ e) { System:: Diagnostics :: Debug :: Print ( "Hope2" ) ; }
static void Hoge3( Object^ sender, EventArgs^ e) { System:: Diagnostics :: Debug :: Print ( "Hope3" ) ; }
} ;
}
dXNpbmcgbmFtZXNwYWNlIFN5c3RlbTsKCm5hbWVzcGFjZSBEZWxlZ2F0ZQp7CglyZWYgY2xhc3MgSG9nZQoJewoJcHVibGljOgoJCWV2ZW50IEV2ZW50SGFuZGxlcl4gUGl5bzsKCQlIb2dlKCkgeyB9CgkJdm9pZCBSYWlzZSgpIHsgUGl5byhudWxscHRyLCBFdmVudEFyZ3M6OkVtcHR5KTsgfQoJfTsKCglyZWYgY2xhc3MgUHJvZ3JhbQoJewoJCXN0YXRpYyB2b2lkIE1haW4oKQoJCXsKCQkJSG9nZV4gaG9nZSA9IGdjbmV3IEhvZ2U7CgkJCWhvZ2UtPlBpeW8gKz0gZ2NuZXcgRXZlbnRIYW5kbGVyKCZIb2dlMSk7CgkJCWhvZ2UtPlBpeW8gKz0gZ2NuZXcgRXZlbnRIYW5kbGVyKCZIb2dlMik7CgkJCWhvZ2UtPlBpeW8gKz0gZ2NuZXcgRXZlbnRIYW5kbGVyKCZIb2dlMyk7CgkJCWhvZ2UtPlJhaXNlKCk7CgoJCQlhdXRvIG1jZCA9IChNd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