params
KeywordThis 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 Type | Name | Arguments |
---|---|---|
int32 scalar RetVal | paramsTest | (netdoc.SampleParamsTest this, |
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 = 21