Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate over an array of dynamic type in C# 4.0?

Tags:

c#-4.0

Hi I have an array of dynamic type which i want to iterate through. But when i say arrayObject.lenght, i get following error:

'object' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'object' could be found

how do i iterate over the array?

[Update]

I post a custom json object using jquery ajax and i have written a model binder for untyped JSON. Here is a screenshot:

enter image description here

like image 326
Amit Avatar asked Dec 19 '11 18:12

Amit


1 Answers

Found the solution:

foreach (dynamic item in cartJsonObject)
{
   // code here
}

I was trying with for loop and foreach using var type. Changing it to dynamic solved it.

like image 71
Amit Avatar answered Oct 19 '22 04:10

Amit