我有国家数据库喜欢,
Country
-------
England
Germany
Italy
...
我得到这个数据源,
DB.Countries.ToList();
我想要做的是检查新添加的国家是否已经存在,
就是喜欢,
if(DB.Countries.ToList().Contains(newAddedCountry))
{
..............
}
但我不知道如何转换
newAddedCountry
(字符串)到 System.Collections.Generic.List<Country>
.
最佳答案
if(DB.Countries.Any(c => c.Country == newAddedCountry))
{
// exists ..
}
关于c# - 如何在列表中使用 "Contain"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16145660/