我收到以下編譯時錯誤:
「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);
}
}
}
}
}
對不起,您使用的代碼是由我在回答另一個問題時創造的 - 我在那裏有這個錯誤。對不起 - 現在已經修好了。感謝您指出了這一點! –