C#檢討指定對象能否存在於ArrayList聚集中的辦法。本站提示廣大學習愛好者:(C#檢討指定對象能否存在於ArrayList聚集中的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#檢討指定對象能否存在於ArrayList聚集中的辦法正文
本文實例講述了C#檢討指定對象能否存在於ArrayList聚集中的辦法。分享給年夜家供年夜家參考。詳細剖析以下:
C#的ArrayList供給了一個公用的Contains辦法來檢測ArrayList能否包括指定的對象,前往值是一個bool類型
ArrayList alcollect = new ArrayList();
// Add individual items to the collection
string str = "learn csharp";
alcollect.Add(str);
//check existence of object
if(alcollect.Contains(str))
{
Console.WriteLine(alcollect.IndexOf(str));
}
else
{
Console.WriteLine("Not found!");
}
願望本文所述對年夜家的C#法式設計有所贊助。