C#,未分配局部变量的使用

C#, Use of Unsigned Local Variable

GPPermissionCollection Class 没有构造函数,我不知道如何声明或使用它的对象。

GPDomain domain = new GPDomain(sDCName + "." + sDCExtention);
Gpo gpo_background = domain.CreateGpo("August-HCalendarGPO");

GPPermission gp = new GPPermission("Everyone", GPPermissionType.GpoEditDeleteModifySecurity, false) ;
GPPermissionCollection gppc;
gppc.Add(gp);  //This Line Has Error
gpo_background.SetSecurityInfo(gppc);

"gppc.Add(gp);" 有错误“使用无符号局部变量”。 如何解决这个错误? 任何帮助都会很感激

您不能创建 GPPermissionCollection 的实例,因为它的构造函数是 internal。您需要通过 GetSecurityInfo():

从 GPO 获取该集合
GPDomain domain = new GPDomain(sDCName + "." + sDCExtention);
Gpo gpo_background = domain.CreateGpo("August-HCalendarGPO");

GPPermission gp = new GPPermission("Everyone", GPPermissionType.GpoEditDeleteModifySecurity, false) ;

// get permissions collection from gpo
GPPermissionCollection gppc = gpo_background.GetSecurityInfo();

gppc.Add(gp);
gpo_background.SetSecurityInfo(gppc);