共用方式為


UIPermission.Intersect(IPermission) 方法

定義

建立並傳回目前權限與指定權限交集的權限。

public:
 override System::Security::IPermission ^ Intersect(System::Security::IPermission ^ target);
public override System.Security.IPermission Intersect (System.Security.IPermission target);
override this.Intersect : System.Security.IPermission -> System.Security.IPermission
Public Overrides Function Intersect (target As IPermission) As IPermission

參數

target
IPermission

要與目前權限產生交集的權限。 必須與目前權限屬於相同的類型。

傳回

新使用權限,表示目前使用權限和指定使用權限的交集。 如果交集是空的,這個新權限就是 null

例外狀況

target 參數不是 null,而且與目前權限屬於不同的類型。

範例

下列程式代碼範例顯示 方法的行為 Intersect 。 這個範例是提供給 類別之較大範例的 UIPermission 一部分。

注意

程式代碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。

// Intersect creates and returns a new permission that is the intersection of the
// current permission and the permission specified.
void IntersectDemo()
{
    Console::WriteLine("\n**********************  Intersect() Demo ***********************\n");
    UIPermission ^ uiPerm1 = gcnew UIPermission(UIPermissionWindow::SafeTopLevelWindows,UIPermissionClipboard::OwnClipboard);
    UIPermission ^ uiPerm2 = gcnew UIPermission(UIPermissionWindow::SafeSubWindows,UIPermissionClipboard::NoClipboard);
    UIPermission ^ p3 = (UIPermission^)uiPerm1->Intersect(uiPerm2);

        Console::WriteLine("   The intersection of {0} and \n\t{1} = {2} ", uiPerm1->Window,
                               uiPerm1->Window, (nullptr != p3)?p3->Window.ToString():"null");

        Console::WriteLine("   The intersection of " + uiPerm1->Clipboard.ToString() + " and \n\t" +
                uiPerm2->Clipboard.ToString() + " is " + p3->Clipboard.ToString());
}
// Intersect creates and returns a new permission that is the intersection of the
// current permission and the permission specified.
private static void IntersectDemo()
{
    UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows, UIPermissionClipboard.OwnClipboard);
    UIPermission uiPerm2 = new UIPermission(UIPermissionWindow.SafeSubWindows, UIPermissionClipboard.NoClipboard);
    UIPermission p3 = (UIPermission)uiPerm1.Intersect(uiPerm2);

    Console.WriteLine("The intersection of " + uiPerm1.Window.ToString() + " and \n\t" +
        uiPerm2.Window.ToString() + " is " + p3.Window.ToString() + "\n");
    Console.WriteLine("The intersection of " + uiPerm1.Clipboard.ToString() + " and \n\t" +
            uiPerm2.Clipboard.ToString() + " is " + p3.Clipboard.ToString() + "\n");
}
' Intersect creates and returns a new permission that is the intersection of the
' current permission and the permission specified.
Private Shared Sub IntersectDemo()
    Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows, UIPermissionClipboard.OwnClipboard)
    Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows, UIPermissionClipboard.NoClipboard)
    Dim p3 As UIPermission = CType(uiPerm1.Intersect(uiPerm2), UIPermission)

    Console.WriteLine("The intersection of " + uiPerm1.Window.ToString() + " and " + vbLf + vbTab + uiPerm2.Window.ToString() + " is " + p3.Window.ToString() + vbLf)
    Console.WriteLine("The intersection of " + uiPerm1.Clipboard.ToString() + " and " + vbLf + vbTab + uiPerm2.Clipboard.ToString() + " is " + p3.Clipboard.ToString() + vbLf)

End Sub

備註

兩個許可權的交集是描述兩者共同描述之作業集的許可權。 具體來說,它代表目前許可權和指定許可權中,和 UIPermissionClipboard 的最小寬鬆值UIPermissionWindow

適用於