Weird Use Of String.Contains

It took me several seconds to figure out what’s exactly going on in there. Especially if the initialization part of the code is not near the line in question, it’ll get confusing very quickly. To be fair I’ll provide you with an full code example below:

Line 22 checks whether myString contains all elements from the myList list.

In my opinion this code is not very easy understandable. So I wanted to improve the code in question. I like the short code which really does the work. Therefore I decided to keep the line. What I wanted to improve was the readability of the code. Because of that I created an extension method specific to List<string>.

Claudio Bernasconi

Claudio Bernasconi is a professional software developer, Microsoft certified technology specialist, blogger, technology enthusiast and founder of CarParking Schweiz. Since 2010 he works for KMS AG in Lucerne, Switzerland.