문제

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