.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>'.

 Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 15 de Mayo de 2026 a las 0:00
Editada: MathWorks Support Team el 11 de Mayo de 2026 a las 2:48

0 votos

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

Más respuestas (0)

Productos

Versión

R2020a

Community Treasure Hunt

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

Start Hunting!