Pergunta

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.

Foi útil?

Solução

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

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top