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

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2026년 5월 15일 0:00
편집: MathWorks Support Team 2026년 5월 11일 2:48

0 개 추천

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

추가 답변 (0개)

제품

릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!