ConstraintCollection.Contains(String) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- name
- String
The ConstraintName of the constraint.
true
if the collection contains the specified constraint; otherwise, false
.
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
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.
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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: