@ankit goel , Welcome to Microsoft Q&A, you could try to use the Enumerable.Except Method to exclude your unwanted strings.
Here is a code example you could refer to.
OrderedDictionary count = new OrderedDictionary();
count.Add("Other Model", 22);
count.Add("Infinx", 12);
count.Add("Apple", 23);
count.Add("Samsung", 23);
count.Add("test", 45);
count.Add("nokia", 34);
List<string> list = new List<string>();
list.Add("Samsung");
list.Add("Infinx");
list.Add("Other Model");
list.Add("Apple");
var exlist = new List<string>();
exlist.Add("Infinx");
list = list.Except(exlist).ToList();
foreach (var item in list)
{
foreach (var kvp in count.Cast<DictionaryEntry>().Reverse().Reverse())
{
if(item==kvp.Key.ToString())
{
count.Remove(kvp.Key);
count.Insert(list.IndexOf(item), kvp.Key, kvp.Value);
}
}
}
Result:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.