How to make bidimensional arrays with a List?












0















I am using
System::Collection::Generics::List



Say I have a List<String^> example;

I am able to get the 0th element using example[0].



Currently i'm trying to do the following:



List<List<T^>^> test;


But doing: test[0][0] doesn't seem to work at all, like it's not designed for bi-dimensional arrays. Could someone know what am i doing wrong?



This is Windows Forms and i'm forced to use managed structures.










share|improve this question

























  • Just to make sure: You know that you are not using C++?

    – Swordfish
    Nov 15 '18 at 3:45











  • I know, it's cli c++

    – Bata
    Nov 15 '18 at 3:47











  • test[0][0] is correct syntax. You probably did not initialize the list correctly. Don't forget that you have to create a List for each element in the outer List. Copy/paste the compile error or exception if you still have trouble.

    – Hans Passant
    Nov 16 '18 at 14:34
















0















I am using
System::Collection::Generics::List



Say I have a List<String^> example;

I am able to get the 0th element using example[0].



Currently i'm trying to do the following:



List<List<T^>^> test;


But doing: test[0][0] doesn't seem to work at all, like it's not designed for bi-dimensional arrays. Could someone know what am i doing wrong?



This is Windows Forms and i'm forced to use managed structures.










share|improve this question

























  • Just to make sure: You know that you are not using C++?

    – Swordfish
    Nov 15 '18 at 3:45











  • I know, it's cli c++

    – Bata
    Nov 15 '18 at 3:47











  • test[0][0] is correct syntax. You probably did not initialize the list correctly. Don't forget that you have to create a List for each element in the outer List. Copy/paste the compile error or exception if you still have trouble.

    – Hans Passant
    Nov 16 '18 at 14:34














0












0








0








I am using
System::Collection::Generics::List



Say I have a List<String^> example;

I am able to get the 0th element using example[0].



Currently i'm trying to do the following:



List<List<T^>^> test;


But doing: test[0][0] doesn't seem to work at all, like it's not designed for bi-dimensional arrays. Could someone know what am i doing wrong?



This is Windows Forms and i'm forced to use managed structures.










share|improve this question
















I am using
System::Collection::Generics::List



Say I have a List<String^> example;

I am able to get the 0th element using example[0].



Currently i'm trying to do the following:



List<List<T^>^> test;


But doing: test[0][0] doesn't seem to work at all, like it's not designed for bi-dimensional arrays. Could someone know what am i doing wrong?



This is Windows Forms and i'm forced to use managed structures.







winforms list c++-cli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 3:44









Swordfish

9,34811336




9,34811336










asked Nov 15 '18 at 3:39









BataBata

65




65













  • Just to make sure: You know that you are not using C++?

    – Swordfish
    Nov 15 '18 at 3:45











  • I know, it's cli c++

    – Bata
    Nov 15 '18 at 3:47











  • test[0][0] is correct syntax. You probably did not initialize the list correctly. Don't forget that you have to create a List for each element in the outer List. Copy/paste the compile error or exception if you still have trouble.

    – Hans Passant
    Nov 16 '18 at 14:34



















  • Just to make sure: You know that you are not using C++?

    – Swordfish
    Nov 15 '18 at 3:45











  • I know, it's cli c++

    – Bata
    Nov 15 '18 at 3:47











  • test[0][0] is correct syntax. You probably did not initialize the list correctly. Don't forget that you have to create a List for each element in the outer List. Copy/paste the compile error or exception if you still have trouble.

    – Hans Passant
    Nov 16 '18 at 14:34

















Just to make sure: You know that you are not using C++?

– Swordfish
Nov 15 '18 at 3:45





Just to make sure: You know that you are not using C++?

– Swordfish
Nov 15 '18 at 3:45













I know, it's cli c++

– Bata
Nov 15 '18 at 3:47





I know, it's cli c++

– Bata
Nov 15 '18 at 3:47













test[0][0] is correct syntax. You probably did not initialize the list correctly. Don't forget that you have to create a List for each element in the outer List. Copy/paste the compile error or exception if you still have trouble.

– Hans Passant
Nov 16 '18 at 14:34





test[0][0] is correct syntax. You probably did not initialize the list correctly. Don't forget that you have to create a List for each element in the outer List. Copy/paste the compile error or exception if you still have trouble.

– Hans Passant
Nov 16 '18 at 14:34












1 Answer
1






active

oldest

votes


















1














This worked for me: -



        Generic::List<String^>^ normalList = gcnew Generic::List<String^>();

Generic::List<Generic::List<String^>^>^ TwoDList = gcnew Generic::List<Generic::List<String^>^>();

TwoDList->Add(gcnew Generic::List<String^>());
TwoDList->Add(gcnew Generic::List<String^>());

TwoDList[0]->Add("First List - First Entry");
TwoDList[0]->Add("First List - Second Entry");
TwoDList[0]->Add("First List - Third Entry");

TwoDList[1]->Add("Second List - First Entry");
TwoDList[1]->Add("Second List - Second Entry");

String^ sTest = gcnew String(TwoDList[0][1]);

Trace::WriteLine(sTest);


My output window data was: -



First List - Second Entry






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312084%2fhow-to-make-bidimensional-arrays-with-a-listt%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This worked for me: -



            Generic::List<String^>^ normalList = gcnew Generic::List<String^>();

    Generic::List<Generic::List<String^>^>^ TwoDList = gcnew Generic::List<Generic::List<String^>^>();

    TwoDList->Add(gcnew Generic::List<String^>());
    TwoDList->Add(gcnew Generic::List<String^>());

    TwoDList[0]->Add("First List - First Entry");
    TwoDList[0]->Add("First List - Second Entry");
    TwoDList[0]->Add("First List - Third Entry");

    TwoDList[1]->Add("Second List - First Entry");
    TwoDList[1]->Add("Second List - Second Entry");

    String^ sTest = gcnew String(TwoDList[0][1]);

    Trace::WriteLine(sTest);


    My output window data was: -



    First List - Second Entry






    share|improve this answer




























      1














      This worked for me: -



              Generic::List<String^>^ normalList = gcnew Generic::List<String^>();

      Generic::List<Generic::List<String^>^>^ TwoDList = gcnew Generic::List<Generic::List<String^>^>();

      TwoDList->Add(gcnew Generic::List<String^>());
      TwoDList->Add(gcnew Generic::List<String^>());

      TwoDList[0]->Add("First List - First Entry");
      TwoDList[0]->Add("First List - Second Entry");
      TwoDList[0]->Add("First List - Third Entry");

      TwoDList[1]->Add("Second List - First Entry");
      TwoDList[1]->Add("Second List - Second Entry");

      String^ sTest = gcnew String(TwoDList[0][1]);

      Trace::WriteLine(sTest);


      My output window data was: -



      First List - Second Entry






      share|improve this answer


























        1












        1








        1







        This worked for me: -



                Generic::List<String^>^ normalList = gcnew Generic::List<String^>();

        Generic::List<Generic::List<String^>^>^ TwoDList = gcnew Generic::List<Generic::List<String^>^>();

        TwoDList->Add(gcnew Generic::List<String^>());
        TwoDList->Add(gcnew Generic::List<String^>());

        TwoDList[0]->Add("First List - First Entry");
        TwoDList[0]->Add("First List - Second Entry");
        TwoDList[0]->Add("First List - Third Entry");

        TwoDList[1]->Add("Second List - First Entry");
        TwoDList[1]->Add("Second List - Second Entry");

        String^ sTest = gcnew String(TwoDList[0][1]);

        Trace::WriteLine(sTest);


        My output window data was: -



        First List - Second Entry






        share|improve this answer













        This worked for me: -



                Generic::List<String^>^ normalList = gcnew Generic::List<String^>();

        Generic::List<Generic::List<String^>^>^ TwoDList = gcnew Generic::List<Generic::List<String^>^>();

        TwoDList->Add(gcnew Generic::List<String^>());
        TwoDList->Add(gcnew Generic::List<String^>());

        TwoDList[0]->Add("First List - First Entry");
        TwoDList[0]->Add("First List - Second Entry");
        TwoDList[0]->Add("First List - Third Entry");

        TwoDList[1]->Add("Second List - First Entry");
        TwoDList[1]->Add("Second List - Second Entry");

        String^ sTest = gcnew String(TwoDList[0][1]);

        Trace::WriteLine(sTest);


        My output window data was: -



        First List - Second Entry







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 14:12









        ZedLepplinZedLepplin

        135




        135






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312084%2fhow-to-make-bidimensional-arrays-with-a-listt%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Xamarin.form Move up view when keyboard appear

            JBPM : POST request for execute process go wrong