How to make bidimensional arrays with a List?
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
add a comment |
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
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
add a comment |
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
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
winforms list c++-cli
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 16 '18 at 14:12
ZedLepplinZedLepplin
135
135
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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