2024-11-07 20:48:25
简单看一下:
List<string> dataList = new List<string>() { "abc", "bcd", "cde" };
//1、循环查找
List<string> dataList1 = new List<string>();
foreach (string item in dataList)
{
if (item.Contains("b"))
{
dataList1.Add(item);
}
}
Console.WriteLine("循环方式:{0}", string.Join(",", dataList1.ToArray()));
//2、条件函数
IEnumerable<string> dataList2 = dataList.Where((s) => s.Contains("b"));
Console.WriteLine("函数方式:{0}", string.Join(",", dataList2.ToArray()));
Console.ReadKey();