A company that shall remain unnamed has IFormsCollection.GetForms("ObjectIndex") || IFormsCollection.GetForms(0) method that throws an exception if the Form isn't in the collection. It isn't IEnumerable<form> and requires either for() loops or .GetEnumerator() -> while() to get each item in the list.

My question is whether or not I should loop through the IForms collection every time? I need to find a form that won't be in there most of the time, or just skip looping and assume if it throws an exception that it's not there? I'd rather not maintain a second collection that IS IEnumerable for ease of searching.

有帮助吗?

解决方案

Exceptions kill performance. You could loop obviously if you want, but it be much faster if ou build a dictionary from this collection with the key being the name and value being the form. then simply search the dictionary for the key and that would be hell lot faster and no exceptions

其他提示

Don't throw exceptions on purpose. They should not be used for normal control flow.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top