如何检查对象/字符串是否已经存在于列表中并且它是否存在以便如何获取它 [英] how to check if object/string already exists in a list and its exists so how can get that

查看:66
本文介绍了如何检查对象/字符串是否已经存在于列表中并且它是否存在以便如何获取它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列表包含大量的手机号码,当我将msg发送到号码然后检查列表中存在的号码或存在然后直接发送

list is contains lots of mobile number when i send the msg to number then check the number in exists in list or exists then directly send

推荐答案

试试
bool alreadyExists = myList.Any(x=> x.mobileNumber==mobileNoToSearch);
if (alreadyExists) {
  //Do sending stuff
}


或尝试(如果使用<$ c) $ c>列表)



or try (if working with List)

List<string> list=new List<string>();
bool isInList=list.Contains("some string");


List<string> mobiles = new List<string>() {"077777777", "0777777778"};
if (mobiles.Contains("077777779"))
   {
   ...
   }


这篇关于如何检查对象/字符串是否已经存在于列表中并且它是否存在以便如何获取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆