public virtual int LastIndexOf(Object value, int startIndex) { if (startIndex >= _size) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); Contract.Ensures(Contract.Result<int>() < Count); Contract.EndContractBlock(); return LastIndexOf(value, startIndex, startIndex + 1); }
public void TestLastIndexOfBasic() { //-------------------------------------------------------------------------- // Variable definitions. //-------------------------------------------------------------------------- ArrayList arrList = null; int ndx = -1; // // Construct array lists. // arrList = new ArrayList((ICollection)strHeroes); // // [] Obtain last index of "Batman" items. // ndx = arrList.LastIndexOf("Batman"); if (ndx != -1) { Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx])); } // // [] Attempt to find null object. // // Remove range of items. ndx = arrList.LastIndexOf(null); Assert.Equal(-1, ndx); // [] Call LastIndexOf on an empty list var myList = new ArrayList(); var lastIndex = myList.LastIndexOf(6); Assert.Equal(-1, lastIndex); }