I see no sense in your code and in formulation of the problem at all. Not even close. I'm almost sure that you do something wrong.
So, let me answer formally.
System.Collections.Generic.Dictionary<KEY, VALUE>
helps to find
VALUE
by
KEY
instance. It gives you
time complexity of O(1), for the following operations:
Dictionary(TKey, TValue).ContainsKey Method (TKey) (System.Collections.Generic)[
^],
Dictionary(TKey, TValue).TryGetValue Method (TKey, TValue) (System.Collections.Generic)[
^].
It should explain you how to search in dictionary. If you do something else, you don't need dictionary at all. And you are doing "something else".
You never really use your dictionary for anything useful. (Please see my comments to the question.) You use
Keys.ToList()
, but you could have only the list of the instances of
RichTextBox
. Also, there is no need to have this member "publicly shared". The
internal access modifiers would do it. It's better not to give more access than it's really required. And it seems highly suspicious to me that you use a timer. We can discuss it only if you explain the goal.
You search in your list anyway. Slowly, at O(N). Moreover, you do your operation for all list elements meeting certain condition. You can also do it using LINQ or this method:
List(T).ForEach Method (Action(T)) (System.Collections.Generic)[
^].
However, I don't think it makes any sense. You should better explain the ultimate goal of all this activity.
—SA