有幾種方法,這裏是一個簡單的例子:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<ColumnDiff> columnDiffs = new List<ColumnDiff>();
columnDiffs.AddRange(new[] {
new ColumnDiff(){columnName="Aa"}
,new ColumnDiff(){columnName="A"}
,new ColumnDiff(){columnName="B"}
,new ColumnDiff(){columnName="Bb"}
,new ColumnDiff(){columnName="C"}
,new ColumnDiff(){columnName="Cc"}
});
bool hasItems = columnDiffs.Exists(x => x.columnName == "A" || x.columnName == "B" || x.columnName == "C");
hasItems = columnDiffs.Any(x => x.columnName == "A" || x.columnName == "B" || x.columnName == "C");
hasItems = columnDiffs.FirstOrDefault(x => x.columnName == "A" || x.columnName == "B" || x.columnName == "C") != null;
Console.ReadKey();
}
}
public class ColumnDiff
{
public string columnName;
public string leftValue;
public string rightValue;
}
}