|On this page…|
You often need to create objects when working with .NET classes. An object is an instance of a particular class. Methods are functions that operate exclusively on objects of a class. Data types package together objects and methods so that the methods operate on objects of their own type. For more information about objects, see MATLAB Objects.
You construct .NET objects in the MATLAB® workspace by calling the class constructor, which has the same name as the class. The syntax to create a .NET object classObj is:
classObj = namespace.ClassName(varargin)
where varargin is the list of constructor arguments to create an instance of the class specified by ClassName in the given namespace. For an example, see Create .NET Object From Constructor.
To call method methodName:
returnedValue = methodName(classObj,args,...)
For more information, see:
The product documentation for your assembly contains information about its classes. However, you can use the NET.addAssembly command to read basic information about an assembly.
For example, to view the class names of the mscorlib library, type:
asm = NET.addAssembly('mscorlib'); asm.Classes
This assembly has hundreds of entries. You can open a window to the online document for the System namespace reference page on the Microsoft® Developer Network. For information about using this documentation, see To Learn More About the .NET Framework.
Objects created from .NET classes appear in MATLAB as reference types, or handle objects. Calling the delete function on a .NET handle releases all references to that .NET object from MATLAB, but does not invoke any .NET finalizers. The .NET Framework manages garbage collection.
For more information about managing handle objects, see Destroying Objects.