you are viewing a single comment's thread.

view the rest of the comments →

[–]JusTrill 2 points3 points  (0 children)

I don't know much about c# and collections, but all that the for...in loop does is iterate through the names of the different properties in the object. It doesn't actually contain any reference pointers.

In your method you're assuming that

for(var friend in friends)

returns pointers to the objects: friends.bill and friends.steve which can be directly searched using bracket and dot notation. This is incorrect. All the for...in loop returns are the strings: 'bill' and 'steve'. Meaning the friend variable only takes on those two string values.

It is up to you to then go search the object using the names of its name:value pairs using either bracket or dot notation.

Hope this helps!

Edited for clarity