check the code below please:
static void Main(string[] args) {
IList<dynamic> items = new List<dynamic>();
items.Add(3);
items.Add("solid");
dynamic i = new ExpandoObject();
items.Add(i); //System.Collections.Generic.IList<object>' does not contain a definition for 'Add'
Console.WriteLine();
}
is this a bug in "dynamic" mechanism?
Looks like a bug (or is it a feature request?):
https://connect.microsoft.com/VisualStudio/feedback/details/534288/ilist-dynamic-cannot-call-a-method-add-without-casting
This should do the trick:
static void Main(string[] args) {
IList<dynamic> items = new List<dynamic>();
items.Add(3);
items.Add("solid");
dynamic i = new ExpandoObject();
items.Add((object) i); // type-cast dynamic object
Console.WriteLine();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With