The dynamic
keyword in C# will let me do something like this:
dynamic obj = ....;
var foo = obj.foo;
where the property reference obj.foo
is resolved at runtime.
Since the property is resolved at runtime, why can't you specify the property itself as a variable? For example,
var propName = "foo";
var foo = obj[propName];
?
I'm aware you can accomplish something like that through reflection or by converting the object to a Dictionary. I'm not interested in the solution as an explanation for why C# doesn't support Javascript-like square bracket lookup in the first place.