简体   繁体   中英

How to remove a string from Dictionary<>

i have used dictionary to collect the array of values

i have value in DataTable .

How to compare the values get from DataTable, whether dictionary key contains the name in DataTable. if DataTable has not that value,then remove that key name from dictionary.

My code:

DataTable dtcolumnsname = clsServiceManager.Instnce.Get_ColumnNames(ClsUserInfo.UserName, strTableName);
Dictionary<string,string> FinalDicColumnVal = new Dictionary<string,string>();

foreach (KeyValuePair<string, string> item in ColumnValues)
{
   if (dtcolumnsname.Columns.Contains(item.Key))
   {
       FinalDicColumnVal.Add(item.Key, item.Value);
   }
}

but this if (dtcolumnsname.Columns.Contains(item.Key)) is not get values of each datarow items in datatable.how to compare the dt row values with dictionary key names

You may make list of values from DataTable, and then work with this list.

List<String> list = new List<string>();
foreach (DataRow row in dtcolumnsname.Rows)
{
    list.Add((string) row["ColumnName"]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM