Not only "flawed", but also "flawless" fragment is so wrong that it's really awkward to explain it. First of all, as
Contains
returns Boolean (and not nullable
Boolean?
), the is no point comparing it with true or false:
bool something =
if (something == true) { }
if (something) { }
The second think revealing having no clue on how programming is done is "else if". The code is equivalent to
if (hashEntries.Contains(someText))
else if (!hashEntries.Contains(someText))
The problem here is the second check: "else if" should be replaced with "if". By the way, it could be not the same if some function or property calculated twice could have some
side effect which could make the result of the second call different from first one, but of course this is not the case.
Now, worst thing: both fragments of "code" are incorrect just because it can throw unwanted exception. Say,
lvSums.SelectedItems[0]
is not necessarily successful, because the number of selected items could be null. If it is successful,
lvSums.SelectedItems[0].SubItems[1]
is not necessarily successful, because number of sub-items can be less than 2.
Further detail could be found through the use of the designer. Such questions generally make little to know sense, but I hope my answer can help to understand what is really flawed and what you need to learn. The flawed is your very basic coding skills, and what you have to learn is: programming requires using some brain and understanding each like you write.
—SA