PrincipalCollection.Contains Method

Definition

Returns a value that indicates whether the specified Principal is a member of the PrincipalCollection. The Principal can be specified in the same manner as in the Add methods.

Overloads

Contains(ComputerPrincipal)

Returns a value indicating whether the collection contains the specified ComputerPrincipal object.

Contains(GroupPrincipal)

Returns a value indicating whether the collection contains the specified GroupPrincipal object.

Contains(Principal)

Returns a value indicating whether the collection contains the specified Principal object.

Contains(UserPrincipal)

Returns a value indicating whether the collection contains the specified UserPrincipal object.

Contains(PrincipalContext, IdentityType, String)

Returns a value indicating whether the Principal object matching the identityType/identityValue pair is in the collection.

Remarks

As with Add, and Remove there are four overloads to this function, but they all do the same thing. The extra overloads are only implemented to improve usability, so that developers using IntelliSense see overloads that take a UserPrincipal, GroupPrincipal, or ComputerPrincipal object. Calling any one of the User, Group, or Computer overloads is exactly equivalent to calling the Principal overload.

Contains(ComputerPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Returns a value indicating whether the collection contains the specified ComputerPrincipal object.

public bool Contains (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);

Parameters

Returns

true if the collection contains the specified object; otherwise, false.

Attributes

Applies to

.NET 9 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Contains(GroupPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Returns a value indicating whether the collection contains the specified GroupPrincipal object.

public bool Contains (System.DirectoryServices.AccountManagement.GroupPrincipal group);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.GroupPrincipal group);

Parameters

group
GroupPrincipal

A GroupPrincipal object.

Returns

true if the collection contains the specified object; otherwise, false.

Attributes

Applies to

.NET 9 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Contains(Principal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Returns a value indicating whether the collection contains the specified Principal object.

public bool Contains (System.DirectoryServices.AccountManagement.Principal principal);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.Principal principal);

Parameters

principal
Principal

A Principal object.

Returns

true if the collection contains the specified object; otherwise, false.

Implements

Attributes

Applies to

.NET 9 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Contains(UserPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Returns a value indicating whether the collection contains the specified UserPrincipal object.

public bool Contains (System.DirectoryServices.AccountManagement.UserPrincipal user);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.UserPrincipal user);

Parameters

user
UserPrincipal

A UserPrincipal object.

Returns

true if the collection contains the specified object; otherwise, false.

Attributes

Applies to

.NET 9 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Contains(PrincipalContext, IdentityType, String)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Returns a value indicating whether the Principal object matching the identityType/identityValue pair is in the collection.

public bool Contains (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
[System.Security.SecurityCritical]
public bool Contains (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);

Parameters

context
PrincipalContext

The PrincipalContext object of the principal.

identityType
IdentityType

An IdentityType object that specifies the format of identityValue.

identityValue
String

A string that identifies the principal, in the format specified by identityType.

Returns

true if an object matching the identityType/identityValue pair is in the collection; otherwise, false.

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
MultipleMatchesException There are multiple principals matching these parameters.
ArgumentException The identityType parameter cannot be empty.

Applies to

.NET 9 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)