Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create Delegate Instances Bound to .NET Methods

For a C# delegate defined as:

namespace MyNamespace
{
  public delegate void MyDelegate();
}

MATLAB® creates the following constructor signature.

Return TypeNameArguments
MyNamespace.MyDelegate objMyDelegate(target,
string methodName)

The argument target is one of the following:

  • An instance of the invocation target object when binding to the instance method

  • A string with fully qualified .NET class name when binding to a static method

methodName is a string specifying the callback method name.

Example — Create a Delegate Instance Associated with a .NET Object Instance Method

For the following C# delegate and class definition:

namespace MyNamespace
{
  public delegate void MyDelegate();

  public class MyClass
  {
    public void MyMethod(){}
  }
}

To instantiate the delegate in MATLAB, type:

target = MyNamespace.MyClass();
delegate = MyNamespace.MyDelegate(target,'MyMethod');

Example — Create a Delegate Instance Associated with a Static .NET Method

For the following C# delegate and class definition:

namespace MyNamespace
{
  public delegate void MyDelegate();

  public class MyClass
  {
    public static void MyStaticMethod(){}
  }
}

To instantiate the delegate in MATLAB, type:

delegate = MyNamespace.MyDelegate('MyNamespace.MyClass','MyStaticMethod');

Related Examples

Was this topic helpful?