Why do I get an error about array formation and indexing while using .NET CopyTo method?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 16 Jun. 2020
Beantwortet: MathWorks Support Team
am 10 Dez. 2020
I'm using a .NET library, one of the classes I'm using implements the Collection interface, but when I try to call the 'CopyTo' method I get an error message:
>> myCollection = MyLibrary.GetCollection(); % Returns a collection of LibObject objects
>> myArr = NET.createArray('System.Object', 200)
>> myCollection.CopyTo(myArr, 0);
Array formation and indexing are not allowed on .NET objects. Use the Item method to index into this object
How can I resolve this error message?
Akzeptierte Antwort
MathWorks Support Team
am 16 Jun. 2020
Make sure that the array that you are copying to is of the same type as the original collection, and be sure that it is large enough to hold the original collection:
>> myArr = NET.createArray('MyLibrary.LibObject', myCollection.Count())
>> myCollection.CopyTo(myArr, 0)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!