c# - How can you get the non-intersected portion of two lists of strings? -


i have 2 lists of strings, illustrated comma-separated below. how can inverse of intersection (i.e. items in 1 or other list not both?

for example:

string test1 = "word1,word2,word3,word4"; string test2 = "word2,word4"; 

in example, looking "word1" , "word3" since each occur in 1 list.

public static void test()     {         string test1 = "word1,word2,word3,word4";         string test2 = "word2,word4";          list<string> test1list = test1.split(',').tolist();         list<string> test2lists = test2.split(',').tolist();         list<string> result = new list<string>();          foreach (var item in test1list)         {             if (!test2lists.contains(item))             {                 if (result.any())                 {                     result.add(","  +item );                 }                 else                 {                     result.add(item);                 }              }         }          result.foreach(p => console.write(p));         console.readline();     } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -