在.NET中使用.NET类库

在.NET应用程序中使用库编译器创建的.NET类库,按照下面的步骤进行操作。[大谦MATLAB,dqmatlab点com]

在机器上引用类库。

引用matlabroot\toolbox\dotnetbuilder\bin\architecture\framework_version目录下的MWArray组件。

在客户程序中使用库编译器生成的组件,必须为MATLAB数据转换集引用名字空间,即在VB.NET中

code.vb.net
Imports MathWorks.MATLAB.NET.Arrays

或在VC#.NET中

code.vc#.net
Using MathWorks.MATLAB.Arrays;

为.NET类库引用名字空间,如在VB.NET中

code.vb.net
Imports MyComponentName
Dim classInstance As MyComponentClass
classInstance=New MyComponentClass

或在VC#.NET中

code.vc#.net
using MyComponentName;
MyComponentClass classInstance=new MyComponentClass();

初始化生成的类库类并调用类方法。使用MWArray数据转换类在本地.NET类型和MATLAB数组类型之间进行转换。

假设组件名为MyComponentName,希望在名为MyApp.cs的程序中使用它。下面是用在MyApp.cs开始部分的声明,在VB.NET中

code.vb.net
Imports System
Imports MathWorks.MATLAB.NET.Arrays
Imports MyComponentName

或在VC#.NET中

code.vc#.net
using System;
using MathWorks.MATLAB.Arrays;
using MyComponentName;

创建和测试.NET应用程序。

创建一个包含.NET类库所需文件的程序安装包。