Main Content

Call .NET Methods With out Keyword

This example shows how to call methods that use an out keyword in the argument list.

The output argument db2 in the following outTest method is modified by the out keyword.

using System;
namespace netdoc
    public class SampleOutTest
        //test out keyword
        public void outTest(double db1, out double db2)
            db1 = db1 * 2.35;
            db2 = db1;

The function signature in MATLAB® is:

Return TypeNameArguments
double scalar db2outTest(netdoc.SampleOutTest this,
double scalar db1)

Create an assembly from the SampleOutTest code, using instructions in Build a .NET Application for MATLAB Examples.

Create an asmpath variable set to the full path to the DLL file, SampleOutTest.dll, created by your development tool. For example:

asmpath = 'c:\work\Visual Studio 2012\Projects\SampleOutTest\SampleOutTest\bin\Debug\';
asmname = 'SampleOutTest.dll';

Load the assembly.

asm = NET.addAssembly(fullfile(asmpath,asmname));

Call the method.

cls = netdoc.SampleOutTest;
db3 = outTest(cls,6)
db3 =

Related Examples

More About