Integrate a .NET Assembly Into a C# Application
This example shows how to call a .NET assembly from a C# application. To create the .NET assembly from your MATLAB® function, see Generate .NET Assembly and Build .NET Application.
Install the .NET assembly from the
The generated shared libraries and support files are located in the
Open Microsoft® Visual Studio® and create a project. For this example, create a C# Console Application called MainApp and create a reference to your assembly file
Add a reference to the
If MATLAB is installed on your system
If MATLAB Runtime is installed on your system
Go to Build > Configuration Manager and change the platform from Any CPU to x64.
Copy the following C# code into the project and save it.
After you finish writing your code, build and run it with Microsoft Visual Studio.
When calling your component, you can take advantage of implicit conversion from .NET
types to MATLAB types, by passing the native C# value directly to
input = 5; obj.makesquare(1, input);
You can also use explicit conversion:
input = new MWNumericArray(5); obj.makesquare(1, input);