日期:2014-05-20 浏览次数:20872 次
public static void Main() { string[] str = { "abc", "bc", "cd", "ef" }; var list = (from a in str where a.Contains('c') select a).ToList(); var list2 = (from a in str where a.Contains('b') select a).ToList(); List<string> ll = new List<string>(); ll.AddRange(list); ll.AddRange(list2); foreach(var cc in ll) Console.WriteLine(cc); }
------解决方案--------------------
string[] arr = { "abc", "bc", "cd", "ef","c1","a2","b2"}; string[] str = { "a", "b", "c" }; List<string> list = new List<string>(); foreach (var c in str) { list.AddRange(arr.Where(n => n.Contains(c)).ToList()); //or Concat //list = (list.Concat(arr.Where(n => n.Contains(c)))).ToList(); } foreach (var o in list) Console.WriteLine(o); Console.ReadLine();