共用方式為


GenericPrincipal.IsInRole(String) 方法

定義

判斷目前的 GenericPrincipal 是否屬於指定的角色。

public:
 override bool IsInRole(System::String ^ role);
public:
 virtual bool IsInRole(System::String ^ role);
public override bool IsInRole (string role);
public override bool IsInRole (string? role);
public virtual bool IsInRole (string role);
override this.IsInRole : string -> bool
abstract member IsInRole : string -> bool
override this.IsInRole : string -> bool
Public Overrides Function IsInRole (role As String) As Boolean
Public Overridable Function IsInRole (role As String) As Boolean

參數

role
String

用來檢查成員資格的角色名稱。

傳回

如果目前的 GenericPrincipal 是指定角色的成員,則為 true,否則為 false

實作

範例

下列程式代碼顯示 方法的使用 IsInRole 方式。 此程式代碼範例是提供給 類別之較大範例的 GenericPrincipal 一部分。

if ( genericPrincipal->IsInRole( L"NetworkUser" ) )
{
   Console::WriteLine( L"User belongs to the NetworkUser role." );
}
if (genericPrincipal.IsInRole("NetworkUser"))
{
    Console.WriteLine("User belongs to the NetworkUser role.");
}
If (genericPrincipal.IsInRole("NetworkUser")) Then
    WriteLine("User belongs to the NetworkUser role.")
End If

適用於