Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is very easy to achieve this - just build another list during your check instead of the counter and then check the size of the "innerlist". I called it currentSyncSet:</p> <pre><code> static void Main(string[] args) { List&lt;string&gt; playlists = new List&lt;string&gt;(){"more and you", "and us", "more"}; List&lt;string&gt; sync = new List&lt;string&gt;() { "more and you-20120312", "more and you-20120314", "more and you-20120313", "and us-20120313", "and us-20120314", "more-20120314", "more-20120313", "more-20120312" }; StringBuilder sb = new StringBuilder(); sb.Append("&lt;h2&gt;Playlist Information&lt;/h2&gt;\r\n"); HashSet&lt;string&gt; finalSyncResult = new HashSet&lt;string&gt;(); foreach (string play in playlists) { List&lt;string&gt; currentSyncSet = new List&lt;string&gt;(); foreach (string s in sync) { if (s.StartsWith(play)) { currentSyncSet.Add(s); } } foreach (var syncset in currentSyncSet) { if (currentSyncSet.Count &lt; 3) { finalSyncResult.Add("&lt;p class=\"bad\"&gt;" + syncset + "&lt;/p&gt;"); } else { finalSyncResult.Add("&lt;p class=\"good\"&gt;" + syncset + "&lt;/p&gt;"); } } } foreach (var result in finalSyncResult) { sb.Append(result + "\r\n"); } Console.WriteLine(sb.ToString()); Console.ReadKey(); } </code></pre> <p>The Output is then:</p> <pre><code>&lt;h2&gt;Playlist Information&lt;/h2&gt; &lt;p class="good"&gt;more and you-20120312&lt;/p&gt; &lt;p class="good"&gt;more and you-20120314&lt;/p&gt; &lt;p class="good"&gt;more and you-20120313&lt;/p&gt; &lt;p class="bad"&gt;and us-20120313&lt;/p&gt; &lt;p class="bad"&gt;and us-20120314&lt;/p&gt; &lt;p class="good"&gt;more-20120314&lt;/p&gt; &lt;p class="good"&gt;more-20120313&lt;/p&gt; &lt;p class="good"&gt;more-20120312&lt;/p&gt; </code></pre> <p>Greetings</p> <p><strong>Update 1:</strong> Sry, last time, i forgot, that you don't want to have duplicate entries - therefore i added a HashSet in this solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload