共用方式為


CObArray::GetAt

Returns the array element at the specified index.

CObject* GetAt(
   INT_PTR nIndex 
) const;

Parameters

  • nIndex
    An integer index that is greater than or equal to 0 and less than or equal to the value returned by GetUpperBound.

Return Value

The CObject pointer element currently at this index.

Remarks

注意

Passing a negative value or a value greater than the value returned by GetUpperBound will result in a failed assertion.

The following table shows other member functions that are similar to CObArray::GetAt.

Class

Member Function

CByteArray

BYTE GetAt( INT_PTR nIndex ) const;

CDWordArray

DWORD GetAt( INT_PTR nIndex ) const;

CPtrArray

void* GetAt( INT_PTR nIndex ) const;

CStringArray

CString GetAt( INT_PTR nIndex ) const;

CUIntArray

UINT GetAt( INT_PTR nIndex ) const;

CWordArray

WORD GetAt( INT_PTR nIndex ) const;

Example

See CObList::CObList for a listing of the CAge class used in all collection examples.

CObArray arr;

arr.Add(new CAge(21)); // Element 0
arr.Add(new CAge(40)); // Element 1
ASSERT(*(CAge*) arr.GetAt(0) == CAge(21));      

Requirements

Header: afxcoll.h

See Also

Concepts

CObArray Class

CObArray Members

Hierarchy Chart

CObArray::SetAt

CObArray::operator [ ]