#include "stdafx.h"
using namespace System;
delegate String^ MyDelegate();
ref class MyClass
{
public:
String^ f() { return "MyClass::f"; }
String^ g() { return "MyClass::g"; }
String^ h() { return "MyClass::h"; }
};
int main()
{
MyDelegate^ d;
MyClass^ r = gcnew MyClass();
d = gcnew MyDelegate(r, &MyClass::f);
d = (MyDelegate^) d->Combine(d, gcnew MyDelegate(r, &MyClass::g));
d = (MyDelegate^) d->Combine(d, gcnew MyDelegate(r, &MyClass::h));
String^ s = d->Invoke();
Console::WriteLine("Return value was {0}", s);
d = (MyDelegate^) d->Remove(d, gcnew MyDelegate(r, &MyClass::g));
s = d->Invoke();
Console::WriteLine("Return value was {0}", s);
for each (MyDelegate^ del in d->GetInvocationList())
{
s = del->Invoke();
Console::WriteLine("Return value was {0}", s);
}
}