System.Data.ConstraintCollection.IndexOf C# (CSharp) Метод

IndexOf() публичный Метод

Returns the index of the specified .
public IndexOf ( Constraint constraint ) : int
constraint Constraint
Результат int
        public int IndexOf(Constraint constraint)
        {
            if (null != constraint)
            {
                int count = Count;
                for (int i = 0; i < count; ++i)
                {
                    if (constraint == (Constraint)List[i])
                        return i;
                }
                // didnt find the constraint
            }
            return -1;
        }

Same methods

ConstraintCollection::IndexOf ( string constraintName ) : int

Usage Example

Пример #1
0
        internal static void SetAsPrimaryKey(ConstraintCollection collection, UniqueConstraint newPrimaryKey)
        {
            //not null
            if (null == collection)
            {
                throw new ArgumentNullException("ConstraintCollection can't be null.");
            }

            //make sure newPrimaryKey belongs to the collection parm unless it is null
            if (collection.IndexOf(newPrimaryKey) < 0 && (null != newPrimaryKey))
            {
                throw new ArgumentException("newPrimaryKey must belong to collection.");
            }

            //Get existing pk
            UniqueConstraint uc = GetPrimaryKeyConstraint(collection);

            //clear existing
            if (null != uc)
            {
                uc._isPrimaryKey = false;
            }

            //set new key
            if (null != newPrimaryKey)
            {
                newPrimaryKey._isPrimaryKey = true;
            }
        }
All Usage Examples Of System.Data.ConstraintCollection::IndexOf