Main Content

Using .NET Properties

How MATLAB Represents .NET Properties

To view property names, use the properties function.

To get and set the value of a class property, use the MATLAB® dot notation:

x = ClassName.PropertyName;
ClassName.PropertyName = y;

The following example gets the value of a property (the current day of the month):

dtnow = System.DateTime.Now;
d = dtnow.Day;

The following example sets the value of a property (the Volume for a SpeechSynthesizer object):

NET.addAssembly('System.Speech');
ss = System.Speech.Synthesis.SpeechSynthesizer;
ss.Volume = 50;
Speak(ss,'You can use .NET Libraries in MATLAB')

To set a static property, call the NET.setStaticProperty function. For an example, see Set Static .NET Properties.

MATLAB represents public .NET fields as properties.

MATLAB represents .NET properties that take an argument as methods. For more information, see Call .NET Properties That Take an Argument.

How MATLAB Maps C# Property and Field Access Modifiers

MATLAB maps C# keywords to MATLAB property attributes, as shown in the following table.

C# Property KeywordMATLAB Attribute
public, staticAccess = public
protected, private, internalNot visible to MATLAB
get, setAccess = public
GetGetAccess = public, SetAccess = private
SetSetAccess = public, GetAccess = private

MATLAB maps C# keywords to MATLAB field attributes, as shown in the following table.

C# Field KeywordMATLAB Mapping
publicSupported
protected, private, internal, protected internalNot visible to MATLAB

For more information about MATLAB properties, see Property Attributes.