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):
dotnetenv("framework") 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 Keyword | MATLAB Attribute |
---|---|
public , static | Access = public |
protected , private ,
internal | Not visible to MATLAB |
get , set | Access = public |
Get | GetAccess = public ,
SetAccess =
private |
Set | SetAccess = public ,
GetAccess =
private |
MATLAB maps C# keywords to MATLAB field attributes, as shown in the following table.
C# Field Keyword | MATLAB Mapping |
---|---|
public | Supported |
protected , private ,
internal , protected
internal | Not visible to MATLAB |
For more information about MATLAB properties, see Property Attributes.