Main Content

ref 키워드를 갖는 .NET 메서드 호출하기

이 예제에서는 인수 목록에 ref 키워드를 사용하는 메서드를 호출하는 방법을 보여줍니다.

다음 refTest 메서드의 입력 인수 db1ref 키워드에 의해 수정됩니다.

using System;
namespace netdoc
{
    public class SampleRefTest
    {
        //test ref keyword
        public void refTest(ref double db1)
        {
            db1 = db1 * 2;
        }
    }
}

MATLAB®의 함수 시그니처는 다음과 같습니다.

반환 유형이름인수
double scalar db1refTest(netdoc.SampleRefTest this,
double scalar db1)

MATLAB 예제용 .NET 애플리케이션 빌드하기(Build a .NET Application for MATLAB Examples)의 지침을 사용하여 SampleRefTest 코드에서 어셈블리를 생성합니다.

개발 툴로 생성된 DLL 파일 SampleRefTest.dll의 전체 경로로 설정된 asmpath 변수를 만듭니다. 예를 들면 다음과 같습니다.

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

어셈블리를 불러옵니다.

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

메서드를 호출합니다.

cls = netdoc.SampleRefTest;
db4 = refTest(cls,6)
db4 =
    12

관련 예제

세부 정보