除暖

C#中怎么判断一个数组中是否存在某个数值

电脑版发表于:2022/4/8 9:46


(1) 第一种方法:

int[] ia = {1,2,3};int id = Array.IndexOf(ia,1); // 这里的1就是你要查找的值if(id==-1)// 不存在else// 存在

 

(2) 第二种方法:

string[] strArr = {"a","b","c","d","e"};bool exists = ((IList)strArr).Contains("a");if(exists)// 存在else// 不存在


转载:https://www.cnblogs.com/superelement/p/7691229.html

关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢