Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


DataColumnCollection.Contains(String) Method

Definition

Checks whether the collection contains a column with the specified name.

C#
public bool Contains(string name);

Parameters

name
String

The ColumnName of the column to look for.

Returns

true if a column exists with this name; otherwise, false.

Examples

The following example uses the Contains method and the CanRemove method to determine whether the column can be removed. If so, the column is removed.

C#
private void RemoveColumn(string columnName, DataTable table)
{
    DataColumnCollection columns = table.Columns;

    if (columns.Contains(columnName))
        if (columns.CanRemove(columns[columnName]))
            columns.Remove(columnName);
}

Remarks

Use the Contains method to confirm the existence of a column before you perform additional operations on the column. The method returns false when two or more columns have the same name but different namespaces. The call does not succeed if there is any ambiguity when matching a column name to exactly one column.

Applies to

Termék Verziók
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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