查找整数列表中是否存在整数 [英] find if an integer exists in a list of integers
本文介绍了查找整数列表中是否存在整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
List<T> apps = getApps();
List<int> ids;
List<SelectListItem> dropdown = apps.ConvertAll(c => new SelectListItem
{
Selected = ids.Contains(c.Id),
Text = c.Name,
Value = c.Id.ToString()
}).ToList();
ids.Contains
似乎总是返回false虽然数字匹配
seems to always return false even though the numbers do match
任何想法?
推荐答案
如果你只需要一个真/假的结果
If you just need a true/false result
bool isInList = intList.IndexOf(intVariable) != -1;
如果列表中不存在intVariable,它将返回-1
if the intVariable does not exist in the List it will return -1
这篇关于查找整数列表中是否存在整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文