C#判斷某元素是否存在數組中


 

 

string s = "K2:CENTALINE\\lukshing|K2:CENTALINE";
string[] s1 = s.Split('|');

//判斷方式是 等於 而不是 Like
Console.WriteLine(Array.IndexOf(s1, "K2:CENTALINE"));//0存在這個是在vs2017上測試出來的   1存在這個是vs2010上試出來的
Console.WriteLine(Array.IndexOf(s1, "K2"));//-1不存在
            
//判斷方式是 等於 而不是 Like
string[] strArr = { "abc", "bcd", "cde", "def", "efh" };
bool exists = ((System.Collections.IList)strArr).Contains("abc");//True
Console.WriteLine(exists);
exists = ((System.Collections.IList)strArr).Contains("a");//False
Console.WriteLine(exists);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM