【发布时间】:2014-05-21 22:52:35
【问题描述】:
在下面的代码中,return 语句正在抛出异常。
private IEnumerable<DirectoryEntry> GetDomains()
{
ICollection<string> domains = new List<string>();
// Querying the current Forest for the domains within.
foreach (Domain d in Forest.GetCurrentForest().Domains)
{
domains.Add(d.Name);
}
return domains; //doesn't work
}
有什么办法可以解决这个问题?
【问题讨论】:
-
当方法的返回类型是 DirectoryEntry 的 IEnumerable 时,您正在尝试返回字符串集合
-
您的示例没有意义 - 您尝试返回
IEnumerable<DirectoryEntry>而是返回字符串集合...您实际尝试实现的目标缺少一些解释。
标签: c# asp.net active-directory