【发布时间】:2011-12-24 09:05:16
【问题描述】:
我正在编写的一些 c# 代码有问题,我对 c# 还很陌生,我环顾四周,找不到解决方案。
我有一个返回字典的方法,我已经将返回类型设置为对象,看起来没问题。
public object loopThroughNotificationCountQueries()
{
var countQuery = new Dictionary<string, string>(); ...
... return countQuery;
}
问题出在我试图遍历从字典返回的元素的主要方法中。
Notification notification = new Notification();
var countDictionary = notification.loopThroughNotificationCountQueries();
foreach(KeyValuePair<String, String> entry in countDictionary)
{
...
}
我收到一条错误消息,提示“错误 2 foreach 语句无法对 'object' 类型的变量进行操作,因为 'object' 不包含 'GetEnumerator' 的公共定义”
是因为我没有为字典指定正确的返回类型吗?还是有另一种方法可以遍历返回对象中的条目?
感谢您的帮助, 斯蒂芬。
【问题讨论】:
标签: c# types dictionary return