Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 查找名称为空的用户主体_C#_Directoryservices - Fatal编程技术网

C# 查找名称为空的用户主体

C# 查找名称为空的用户主体,c#,directoryservices,C#,Directoryservices,我想返回所有没有名称的UserPrincipal 使用此代码: List<UserPrincipal> searchPrinciples = new List<UserPrincipal>(); searchPrinciples.Add(new UserPrincipal(ctx) { Name = null }); 使用此搜索参数时,我收到相同的错误: searchPrinciples.Add(new UserPrincipal(ctx) { Name = ""})

我想返回所有没有名称的UserPrincipal

使用此代码:

List<UserPrincipal> searchPrinciples = new List<UserPrincipal>();
searchPrinciples.Add(new UserPrincipal(ctx) { Name = null });
使用此搜索参数时,我收到相同的错误:

 searchPrinciples.Add(new UserPrincipal(ctx) { Name = ""});

根据规范,您不能将
UserPrincipal.Name
设置为
null

“Principal.Name”是主体的名称,如果未设置Name属性,则为null

如果应用程序试图将名称设置为null,则[…]将抛出“ArgumentNullException”

如果希望它为null(或空),就不要全部设置它。默认情况下,它将被初始化为null

如果要搜索所有具有空名称的
UserPrincipal
实例,可以执行以下操作(LINQ):

IEnumerable result=searchPrinciples.Where(p=>String.IsNullOrEmpty(p.Name));

能否显示您的
UserPrincipal
Principal
的外观根据MSDN(),您不能将该属性设置为null。你如何在广告中搜索用户?
 searchPrinciples.Add(new UserPrincipal(ctx) { Name = ""});
IEnumerable<UserPrincipal> result = searchPrinciples.Where(p => String.IsNullOrEmpty(p.Name));