c# - How do I iterate through a Dynamic type array -



c# - How do I iterate through a Dynamic type array -

this question has reply here:

how cast system.object[*] system.object[] 2 answers

i have com reads our vms scheme , returns array dynamic type.

in visual studio when inspect type shows:

dynamic {object[]}

so tried following:

var lines = myapp.getscreenlines(); foreach(var line in lines) { //do }

but maintain getting exception:

unable cast object of type 'system.object[*]' type 'system.object[]'.

however, if inspect lines, shows normal array , can expand see data.

does know how can convert dynamic array info type string type?

i have tried solutions in duplicate link yet dont seem work assume know info array. dynamic dont know until runtime, cant lower or upper bounds of array.

ps have no command on myapp.getscreenlines(); returns com api.

edit:

the solutions provided in duplicate not resolve issue. have tried both.

the first 1 ive tried was:

array sourcearray = mywinformsapp.getscreenlines(); if (sourcearray.rank != 1) throw new invalidoperationexception("expected single-rank array."); object[] newarray2 = new object[sourcearray.length]; array.copy(sourcearray, sourcearray.getlowerbound(0), newarray2, 0, sourcearray.length);

this results in exception: unable cast object of type 'system.object[*]' type 'system.object[]'.

the sec 1 tried was:

object[] newarray = mywinformsapp.getscreenlines().cast<object>().toarray();

to exception: 'system.array' not contain definition 'cast'

so dont consider question duplicate, ive explained can view array using "watch" tool in visual studio, cant seem iterate through it

try using dynamic instead of var

var lines = myapp.getscreenlines(); foreach(dynamic line in lines) { //do }

c# arrays type-conversion

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -