سؤال

I am messing around with this topic a day now. I tried to use Vectors, IVectors and Arrays.

Arrays can't have a higher dimension than 1 in WinRT, Vectors seem to be impossible to use in a public context. (If you can tell me how, please do!) and IVectors are interfaces, so you can't make an IVector of IVectors.

Is there any, and I mean any way to make a real two-dimensional array or an array of arrays like it was possible in C++/CLI?

(And yes, I know I can simulate 2 dimensions with a one dimensional array, but I don't really want to do that.)

هل كانت مفيدة؟

المحلول

I used this workaround for this issue. Not pretty, but functional.

Rather than creating a Vector of Vectors create a Vector of Objects. Then use safe_cast to access Vectors within your containing Vector.

Platform::Collections::Vector<Object^ >^ lArrayWithinArray = ref new Platform::Collections::Vector<Object^ >();

//Prepare some test data
Platform::Collections::Vector<Platform::String^>^ lStrings = ref new  Platform::Collections::Vector<Platform::String^>();
lStrings->Append(L"One");
lStrings->Append(L"Two");
lStrings->Append(L"Three");
lStrings->Append(L"Four");
lStrings->Append(L"Five");

//We will use this to show that it works
Platform::String^ lOutput = L"";

//Populate the containing Vector
for(int i = 0; i < 5; i++)
{
    lArrayWithinArray->Append(ref new Platform::Collections::Vector<String^>());

    //Populate each Vector within the containing Vector with test data
    for(int j = 0; j < 5; j++)
    {
        //Use safe_cast to cast the Object as a Vector
        safe_cast<Platform::Collections::Vector<Platform::String^>^>(lArrayWithinArray->GetAt(i))->Append(lStrings->GetAt(j));
    }
}

//Test loop to verify our content
for(int i = 0; i < 5; i++)
{
    for(int j = 0; j < 5; j++)
    {
        lOutput += lStrings->GetAt(i) + L":" + safe_cast<Platform::Collections::Vector<Platform::String^>^>(lArrayWithinArray->GetAt(i))->GetAt(j) + ", ";
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top