C# ArrayList中的LastIndexof(Object,int32,int32)方法示例
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
//创建一个新的ArrayList
ArrayList myArray = new ArrayList();
myArray.Add("Hi");
myArray.Add("How");
myArray.Add("Are");
myArray.Add("You");
myArray.Add("Hi");
myArray.Add("Have");
myArray.Add("a nice");
myArray.Add("Day");
myArray.Add("Hi");
//查看ArrayList的值
Console.WriteLine("The ArrayList contains the following values:");
foreach (string s in myArray)
{
Console.WriteLine(s);
}
String myString = "Hi";
//在ArrayList的某个部分中搜索该值的最后一个匹配项。注意,开始索引大于结束索引,因为搜索是向后进行的。
int myIndex = myArray.LastIndexOf(myString, 8, 5);
Console.WriteLine("索引5到8之间,最后一次出现{0}的位置为: {1}.", myString, myIndex);
}
}
}
ArryIndexOf(Object,int32 a ,int32 b)ArrayList的方法对指定的对象进行搜索,返回 a到b索引之间最后一个匹配对象的索引
日期:2020-04-11 23:03:44 来源:oir作者:oir
