Export (0) Print
Expand All

AttributeCollection.Matches Method (Attribute[])

Determines whether the attributes in the specified array are the same as the attributes in the collection.

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

public bool Matches(
	Attribute[] attributes


Type: System.Attribute[]

An array of MemberAttributes to compare with the attributes in this collection.

Return Value

Type: System.Boolean
true if all the attributes in the array are contained in the collection and have the same values as the attributes in the collection; otherwise, false.

An attribute can provide support for matching.

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

private void MatchesAttributes() {
   // 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 match the attributes for textBox1.
   Attribute[] myAttrArray = new Attribute[100];
   TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0);
   if (myCollection.Matches(myAttrArray))
      textBox1.Text = "The attributes in the button and text box match.";
      textBox1.Text = "The attributes in the button and text box do not match.";

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft