This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Call .NET Methods With params Keyword

This example shows how to call methods that use a params keyword in the argument list.

The input argument num in the following paramsTest method is modified by the params keyword.

using System;
namespace netdoc
    public class SampleParamsTest
        //test params keyword
        public int paramsTest(params int[] num)
            int total = 0;
            foreach (int i in num)
                total = total + i;
            return total;

The function signature in MATLAB® is:

Return TypeNameArguments
int32 scalar RetValparamsTest(netdoc.SampleParamsTest this,
System.Int32[] num)

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

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

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

Load the assembly.

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

Call the method.

cls = netdoc.SampleParamsTest;
mat  = [1, 2, 3, 4, 5, 6];
db5 = paramsTest(cls,mat)
db5 =

Related Examples

More About