[mono-android] What´s wrong with this piece of code?
Morten Nilsen
mortenn at hapro.no
Fri Mar 11 07:53:11 EST 2011
Hi
I suspect this might be caused by your use of IList/IDictionary for variables..
I’m not sure a List<Dictionary<string,object>> would accept an object of type IDictionary<string,object>..
What if, one day, the curGroupMap is changed to be an instance of MusicalDictionary<string,object>?
You either need to do groupData.Add((Dictionary<string, object>)curGroupMap) or stop casting everything into interfaces, I believe.
If you really do want to have interfaces rather than classes here, your list needs to agree with that.
Not everything has to be an interface, by the way – especially not internally in a method.
-- mvh, Morten
From: monodroid-bounces at lists.ximian.com [mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Carlo Bolz
Sent: Friday, March 11, 2011 1:36 PM
To: Monodroid at lists.ximian.com
Subject: [mono-android] What´s wrong with this piece of code?
Hello,
what´s wrong with this piece of code:
IList<IDictionary<string, object>> groupData = new List<Dictionary<string, object>>() as IList<IDictionary<string, object>>;
IList<IList<IDictionary<string, object>>> childData = new List<List<Dictionary<string, object>>>() as IList<IList<IDictionary<string, object>>>;
for (int i = 0; i < 20; i++)
{
IDictionary<string, object> curGroupMap = new Dictionary<string, object>();
curGroupMap.Add(NAME, "Group " + i.ToString());
curGroupMap.Add(ISEVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
groupData.Add(curGroupMap); // < the app dies here
Any suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110311/f1e39016/attachment.html
More information about the Monodroid
mailing list