Export (0) Print
Expand All

MessageQueuePermissionEntryCollection.AddRange Method (MessageQueuePermissionEntryCollection)

Appends a set of specified permission entries to this collection.

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)

public void AddRange(
	MessageQueuePermissionEntryCollection value
)

Parameters

value
Type: System.Messaging.MessageQueuePermissionEntryCollection

A MessageQueuePermissionEntryCollection that contains the permission entries to add.

The following code example demonstrates the use of AddRange(MessageQueuePermissionEntryCollection).

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

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

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

// Add the entry to the permission's collection.
permission.PermissionEntries.Add(entry);

// Create another new instance of MessageQueuePermission.
MessageQueuePermission newPermission = new MessageQueuePermission();

// Use AddRange() to append the original permission's collection to the 
// new permission's collection.
newPermission.PermissionEntries.AddRange(permission.PermissionEntries);

// To show that AddRange() copies collections by value and not by 
// reference, we'll clear the original permission's collection, then 
// display a count of how many entries are in the original permission's 
// collection and how many entries are in the new permission's 
// collection. 

// Clear the original permission's collection.
permission.PermissionEntries.Clear();

// The original permission now contains 0 entries, but the new 
// permission still contains 1 entry.
Console.WriteLine("Original permission contains {0} entries.",
    permission.PermissionEntries.Count);
Console.WriteLine("New permission contains {0} entries.",
    newPermission.PermissionEntries.Count);

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft