Error when trying to assign to a .NET List Item property

조회 수: 1 (최근 30일)
When I try to assign to a List Item property as:
>> list.Item(0).prop = 1
I get the following error:
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 2020년 6월 30일
This error will occur if the List Item are structs. Since structs are values (i.e. not references) and since List Items are read-only, you will not be able to modify the Item property in this way. You will need to copy the value, modify the copy, and assign it back to the list. For instance:
x = list.Item(0);
x.prop = 1;
list.Item(0,x); % assigns list.Item(0) the value of x
See here for more information on List Items:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 .NET Generic Classes in MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by