Редагувати

Поділитися через


ConstraintCollection.Contains(String) Method

Definition

Indicates whether the Constraint object specified by name exists in the collection.

public:
 bool Contains(System::String ^ name);
public bool Contains (string? name);
public bool Contains (string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

Parameters

name
String

The ConstraintName of the constraint.

Returns

true if the collection contains the specified constraint; otherwise, false.

Examples

The following example determines whether the specified Constraint exists in the ConstraintCollection before its deletion.

public static void RemoveConstraint(
    ConstraintCollection constraints, Constraint constraint)
{
    try
    {
        if(constraints.Contains(constraint.ConstraintName))
        {
            if(constraints.CanRemove(constraint))
            {
                constraints.Remove(constraint.ConstraintName);
            }
        }
    }
    catch(Exception e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}
Public Shared Sub RemoveConstraint( _
    constraints As ConstraintCollection, constraint As Constraint)
    Try
        If constraints.Contains(constraint.ConstraintName) Then
            If constraints.CanRemove(constraint)
                constraints.Remove(constraint.ConstraintName)
            End If
        End If

    Catch e As Exception
        ' Process exception and return.
        Console.WriteLine($"Exception of type {e.GetType()} occurred.")
    End Try
 End Sub

Remarks

Use the Contains method to determine whether the specified Constraint exists before trying to remove it from the collection. You can also use the CanRemove method to determine whether a Constraint can be removed.

Applies to

See also