.NET のリストアイテムのプ​ロパティにアクセスす​るとエラーとなるのは​なぜですか?

リストアイテムのプロパティに次のように割り当てようとすると、
>> list.Item(0).prop = 1
次のエラーが表示されます:
The name 'Item' is not an accessible property for an instance of class
'System.Collections.Generic.List<ClassLibrary1*Example1>'.

 Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 15 Mai 2026 um 0:00
Bearbeitet: MathWorks Support Team am 11 Mai 2026 um 2:48

0 Stimmen

このエラーは、リストが構造体である場合に発生します。構造体は値(つまり参照ではない)であり、リスト項目は読み取り専用であるため、この方法でItemプロパティを変更することはできません。値をコピーし、コピーを変更して、リストに戻す必要があります。
例:
x = list.Item(0);
x.prop = 1;
list.Item(0,x); % assigns list.Item(0) the value of
リスト アイテムの詳細については、こちらを参照してください。

Weitere Antworten (0)

Produkte

Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!