Skip to Main Content Skip to Search
Product Documentation

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):

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

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

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

To set a static property, you must 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.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS