ConstraintCollection.Contains(String) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt aangegeven of het Constraint object dat op naam is opgegeven, bestaat in de verzameling.
public:
bool Contains(System::String ^ name);
public bool Contains(string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean
Parameters
- name
- String
De ConstraintName beperking.
Retouren
true als de verzameling de opgegeven beperking bevat; anders, false.
Voorbeelden
In het volgende voorbeeld wordt bepaald of de opgegeven Constraint bestaat in de ConstraintCollection voordat het wordt verwijderd.
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
Opmerkingen
Gebruik de Contains methode om te bepalen of de opgegeven Constraint bestaat voordat u deze uit de verzameling probeert te verwijderen. U kunt ook de CanRemove methode gebruiken om te bepalen of een Constraint kan worden verwijderd.