boolContains(Titem)// Determines whether an element is in the List<>.
{
for(inti=0;i<_size;i++)
{
if(_items[i]==item)
{
returntrue;
}
}
returnfalse;
}
voidCopyTo(Tarray[])// Copies the entire List<> to a compatible one-dimensional array, starting at the beginning of the target array.
{
Array::Copy(_items,0,array,0,_size);
}
voidCopyTo(Tarray[],intarrayIndex)// Copies the entire List<> to a compatible one-dimensional array, starting at the specified index of the target array.
{
Array::Copy(_items,0,array,arrayIndex,_size);
}
intIndexOf(Titem)// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List<>.
{
returnArray::IndexOf(_items,item,0,_size);
}
voidInsert(intindex,Titem)// Inserts an element into the List<> at the specified index.
{
if(index>_size)
{
throwArgumentOutOfRangeException("index","Index must be within the bounds of the List.");
voidRemoveRange(intindex,intcount)// Removes a range of elements from the List<>.
{
if((index<0)||(count<0))
{
throwArgumentOutOfRangeException((index<0)?"index":"count","Non-negative number required.");
}
if((_size-index)<count)
{
throwArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
throwArgumentOutOfRangeException((index<0)?"index":"count","Non-negative number required.");
}
if((_size-index)<count)
{
throwArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
}
Array::Reverse(_items,index,count);
_version++;
}
T*ToArray()
{
return_items;
}
voidTrimExcess()
{
intnum=(int)(Array::Length(_items)*0.9);
if(_size<num)
{
Capacity(_size);
}
}
Toperator[](intindex)
{
if(index>=_size)
throwArgumentOutOfRangeException("index");
return_items[index];
}
};
/// <summary>
/// Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and
boolContains(T*item)// Determines whether an element is in the List<>.
{
for(inti=0;i<_size;i++)
{
if(_items[i]==item)
{
returntrue;
}
}
returnfalse;
}
voidCopyTo(T*array[])// Copies the entire List<> to a compatible one-dimensional array, starting at the beginning of the target array.
{
Array::Copy(_items,0,array,0,_size);
}
voidCopyTo(T*array[],intarrayIndex)// Copies the entire List<> to a compatible one-dimensional array, starting at the specified index of the target array.
{
Array::Copy(_items,0,array,arrayIndex,_size);
}
intIndexOf(T*item)// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List<>.
{
returnArray::IndexOf(_items,item,0,_size);
}
voidInsert(intindex,T*item)// Inserts an element into the List<> at the specified index.
{
if(index>_size)
{
throwArgumentOutOfRangeException("index","Index must be within the bounds of the List.");
voidRemoveRange(intindex,intcount)// Removes a range of elements from the List<>.
{
if((index<0)||(count<0))
{
throwArgumentOutOfRangeException((index<0)?"index":"count","Non-negative number required.");
}
if((_size-index)<count)
{
throwArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
throwArgumentOutOfRangeException((index<0)?"index":"count","Non-negative number required.");
}
if((_size-index)<count)
{
throwArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");