Create Delegates from .NET Object Methods
This C# class defines the methods AddEggs and
AddFlour, which have signatures matching the
delInteger delegate. To build and load the
Recipe assembly, see Build and Load .NET Assembly for MATLAB. The source code is:
using System;
namespace Recipe
{
public class MyClass
{
public string AddEggs(double n)
{
return "Add " + n + " eggs";
}
public string AddFlour(double n)
{
return "Add " + n + " cups flour";
}
}
}Create a delegate myFunc using AddEggs as the
callback:
myRec = Recipe.MyClass; myFunc = NetDocDelegate.delInteger(@myRec.AddEggs); myFunc(2)
ans = Add 2 eggs