我收到以下编译时错误:
“P”不会在目前情况下
这里是我的代码...有人可以帮助存在的名字吗?谢谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
public static List<string> GetGroups()
{
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
using (p = Principal.FindByIdentity(ctx, "yourUserName"))
{
var groups = p.GetGroups();
using (groups)
{
foreach (Principal group in groups)
{
Console.WriteLine(group.SamAccountName + "-" + group.DisplayName);
}
}
}
}
}
对不起,您使用的代码是由我在回答另一个问题时创造的 - 我在那里有这个错误。对不起 - 现在已经修好了。感谢您指出了这一点! –