ConstraintCollection.Contains(String) Method

Definition

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

public bool Contains (string? name);
public bool Contains (string name);

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());
    }
}

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

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also