MessageQueuePermissionEntryCollection.Add(MessageQueuePermissionEntry) 方法

定义

向此集合添加指定的 MessageQueuePermissionEntry

public:
 int Add(System::Messaging::MessageQueuePermissionEntry ^ value);
public int Add (System.Messaging.MessageQueuePermissionEntry value);
member this.Add : System.Messaging.MessageQueuePermissionEntry -> int
Public Function Add (value As MessageQueuePermissionEntry) As Integer

参数

返回

所添加的 MessageQueuePermissionEntry 的从零开始的索引。

示例

以下代码示例演示了 Add 的用法。

// Connect to a queue on the local computer.
MessageQueue^ queue = gcnew MessageQueue(".\\exampleQueue");

// Create a new instance of MessageQueuePermission.
MessageQueuePermission^ permission = gcnew MessageQueuePermission();

// Get an instance of MessageQueuePermissionEntryCollection from the
// permission's PermissionEntries property.
MessageQueuePermissionEntryCollection^ collection =
    permission->PermissionEntries;

// Create a new instance of MessageQueuePermissionEntry.
MessageQueuePermissionEntry^ entry = gcnew MessageQueuePermissionEntry(
    MessageQueuePermissionAccess::Receive, 
    queue->MachineName, 
    queue->Label, queue->Category.ToString());

// Add the entry to the collection.
collection->Add(entry);

queue->Close();
// Connect to a queue on the local computer.
MessageQueue queue = new MessageQueue(".\\exampleQueue");

// Create a new instance of MessageQueuePermission.
MessageQueuePermission permission = new MessageQueuePermission();

// Get an instance of MessageQueuePermissionEntryCollection from the
// permission's PermissionEntries property.
MessageQueuePermissionEntryCollection collection =
    permission.PermissionEntries;

// Create a new instance of MessageQueuePermissionEntry.
MessageQueuePermissionEntry entry = new MessageQueuePermissionEntry(
    MessageQueuePermissionAccess.Receive,
    queue.MachineName,
    queue.Label,
    queue.Category.ToString());

// Add the entry to the collection.
collection.Add(entry);

适用于