AttributeCollection.Contains Method (Attribute[])


Determines whether this attribute collection contains all the specified attributes in the attribute array.

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

public bool Contains(
	Attribute[] attributes


Type: System.Attribute[]

An array of type Attribute to find in the collection.

Return Value

Type: System.Boolean

true if the collection contains all the attributes; otherwise, false.

This collection has the specified array of attributes if all the specified attribute types exist in the collection and if each attribute in the specified array is the same as an attribute in the collection.

The following code example compares the attributes in button1 and textBox1 to see whether the attributes for the button are contained in the attributes for the text box. It assumes that both button1 and textBox1 have been created on a form.

private void ContainsAttributes() {
   // Creates a new collection and assigns it the attributes for button1.
   AttributeCollection myCollection;
   myCollection = TypeDescriptor.GetAttributes(button1);    

   // Checks to see whether the attributes in myCollection are the attributes for textBox1.
   Attribute[] myAttrArray = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Contains(myAttrArray))
      textBox1.Text = "Both the button and text box have the same attributes.";
      textBox1.Text = "The button and the text box do not have the same attributes.";

.NET Framework
Available since 1.1
Return to top