I am trying to understand c# dynamic. I have an ExpandoObject instance assigned to dynamic variable.
I understand ExpandoObject is implementing IDictionary. But the below assignment fails.
dynamic obj = new ExpandoObject();
obj["Test"] = "TestValue";
Console.WriteLine(obj.Test);
Can someone tell me where i am going wrong?
obj.Test="TestValue";
However the above statement seems to be working fine.
To do that, you need to cast the
ExpandoObjecttoIDictionary<string, object>.This is normal Expando usage:
This is string-literal (or string variable) usage:
If the interface implementation is explicit, you need to cast to a reference of the interface in order to access the members. I’m guessing this is what has happened here.