共用方式為


ForeignKeyConstraint.Equals(Object) 方法

定義

取得值,指出目前的 ForeignKeyConstraint 是否與指定的物件相同。

public:
 override bool Equals(System::Object ^ key);
public override bool Equals (object? key);
public override bool Equals (object key);
override this.Equals : obj -> bool
Public Overrides Function Equals (key As Object) As Boolean

參數

key
Object

這個 ForeignKeyConstraint 所要比較的物件。 如果兩個 ForeignKeyConstraint 約束相同的資料行,則這兩者相等。

傳回

如果物件相同,則為 true,否則為 false

範例

下列範例會建立新的 ForeignKeyConstraint ,並在將它新增至 ConstraintCollection之前,先使用 方法檢查其他集合成員Equals

private void CreateConstraint(DataSet dataSet)
{
   // Create the ForignKeyConstraint with two DataColumn objects.
   DataColumn parentCol = dataSet.Tables["Customers"].Columns["id"];
   DataColumn childCol = dataSet.Tables["Orders"].Columns["OrderID"];
   ForeignKeyConstraint fkeyConstraint =
      new ForeignKeyConstraint("fkConstraint", parentCol, childCol);

   // Test against existing members using the Equals method.
   foreach(ForeignKeyConstraint testConstraint in
       dataSet.Tables["Orders"].Constraints)
   {
      if(fkeyConstraint.Equals(testConstraint)){
         Console.WriteLine("Identical ForeignKeyConstraint!");
          // Insert code to delete the duplicate object,
          // or stop the procedure.
      }
   }
}
Private Sub CreateConstraint(dataSet As DataSet)
    ' Create the ForignKeyConstraint with two DataColumn objects.
    Dim parentCol As DataColumn = _
       dataSet.Tables("Customers").Columns("id")
    Dim childCol As DataColumn = _
       dataSet.Tables("Orders").Columns("OrderID")
    Dim fkeyConstraint As _
       New ForeignKeyConstraint("fkConstraint", parentCol, childCol)

    ' Test against existing members using the Equals method.
    Dim testConstraint As ForeignKeyConstraint
    For Each testConstraint In  dataSet.Tables("Orders").Constraints
        If fkeyConstraint.Equals(testConstraint) Then
            Console.WriteLine("Identical ForeignKeyConstraint!")
            ' Insert code to delete the duplicate object, 
            ' or stop the procedure.
        End If
    Next testConstraint
End Sub

適用於