【发布时间】:2022-10-13 18:18:40
【问题描述】:
假设我有列名:
IList<string> selectedColumn = new List<string>{"Name", "City", "CreatedAt"};
从一些条目进入循环,我正在获取数据:
foreach (Car car in rowsWithAllCar)
{
string name = car.Name;
string lastName = car.LastName;
string city = car.City;
string home = car.Home;
DateTime createdAt= (DateTime)car.CreatedAt;
string[] allItems = {name, lastName, phone, city, createdAt}
}
如何检查例如值 car.LastName 或 car.Home 是否不在 selectedColumn 中?因为我不想将此添加到我的allItems。
结果应该是:
string[] allItems = {name, city, createdAt};
【问题讨论】:
-
您的示例根本不会产生任何结果,因为它只是声明了一个仅在循环内有效的本地
allItems数组。这使得很难理解实际意图是什么。如果您只想检查列表是否包含值,则有List.Contains。
标签: c# .net compare comparison contains