[英]Windows phone 7.5 using C# An unhandled exception of type 'System.InvalidCastException' occurred in appName.dll
Does anyone know the proper way to cast itemCollection.GetEnumerator()? 有谁知道投射itemCollection.GetEnumerator()的正确方法?
For some reasons, return itemCollection.GetEnumerator(); 由于某些原因,返回itemCollection.GetEnumerator();。 works fine in windows phone 8, but doesn't work in windows phone 7.5 It asked me to explicity cast it, but I'm not sure what is the proper way.
在Windows Phone 8中可以正常工作,但在Windows Phone 7.5中不能正常工作。它要求我显式转换它,但我不确定什么是正确的方法。 Does anyone know?
有人知道吗?
public class ItemCollection : IEnumerable<Object>
{
private System.Collections.ObjectModel.ObservableCollection<Item> itemCollection = new System.Collections.ObjectModel.ObservableCollection<Item>();
public IEnumerator<Object> GetEnumerator()
{
//return itemCollection.GetEnumerator();
IEnumerator<Object> test = (IEnumerator<Object>)itemCollection.GetEnumerator();
return test;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Add(Item item)
{
itemCollection.Add(item);
}
}
我不确定,请尝试一下
IEnumerator<Object> test = new IEnumerator<Object>(itemCollection.GetEnumerator());
另外,试试这个
return itemCollection.Cast<object>()
hmm it not clear to me why you want to do this: wouldn't it be better to just do this: 嗯,我不清楚您为什么要这样做:这样做不是更好:
public class ItemCollection : System.Collections.ObjectModel.ObservableCollection<Item>
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.