List string array access

Page 1 of 1

13 Replies - 436 Views - Last Post: 17 June 2019 - 07:14 AM Rate Topic: -----

#1 Realme   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 147
  • Joined: 22-May 19

List string array access

Posted 10 June 2019 - 10:25 AM

I have made List string array by following:

 List<string[]> VLista = new List<string[]>();


I have saved arrays in this list.

However, to get every list written in my for loop does not work, here is example:

for (int i = 0; i < VLista.Count; i++)
                
            {
                
                textBox1.Text = Convert.ToString(VLista[i]);
               

}

I have tried in many various ways it still does not woek. It says:

"System.String[]"

This post has been edited by Realme: 10 June 2019 - 10:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: List string array access

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6968
  • View blog
  • Posts: 23,684
  • Joined: 05-May 12

Re: List string array access

Posted 10 June 2019 - 10:37 AM

How is that the minimal compilable amount of code needed to reproduce the problem? What is textBox1?

What error are you getting? If you are not getting an error, but unexpected behavior, what behavior are you seeing and what behavior were you expecting to see?

View PostRealme, on 10 June 2019 - 01:25 PM, said:

I have tried in many various ways it still does not woek. It says:

"System.String[]"

That is because each item in your list is a string array. C# is not like Javascript or PHP which will dump the contents of an object automatically. (See your old threads from about two weeks ago where you were trying to just pass in object references to your Console.WriteLine() calls.) So similarly here, calling Convert.ToString() on an object -- which in this case is an array -- will not magically convert the contents of the array into a single string.

I suspect part of the issue here is that you like creating compound statements. Just like in your other threads where you insist on doing something like:
new Bok() { Series = Console.ReadLine() }


You are also trying to do too much on a single line with your
textBox1.Text = Convert.ToString(VLista[i]);



Try assigning VLista[i] to a variable. Notice that it an array. How do you access items in an array?

Or the issue maybe that you are not understanding that when you write VLista[i] you are using the List<T> indexer, not the Array indexer.
Was This Post Helpful? 0
  • +
  • -

#3 Realme   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 147
  • Joined: 22-May 19

Re: List string array access

Posted 15 June 2019 - 02:19 PM

Hi,

I have two foreach loops, one inside the other, how do I get it correct?

I want to type out every list string arrays List<string[]> VList

Foreach (var item in VList)
{
Foreach (var b in item)
{
Richtextbox 1 = VList[item][b]?
}
}


How do I get it to wrote out everything inside?

I wrote this on my phone and I know this is not correct because it will go outside exception. How is the correct writing? Also it is supposed to go "+=" and not only "=" to get it in correct arrange underneath.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6968
  • View blog
  • Posts: 23,684
  • Joined: 05-May 12

Re: List string array access

Posted 15 June 2019 - 03:32 PM

Merging with your older thread...

See post #2, in particular the last two paragraphs.

In your post #3, why are you using item and b as indexers into your list of string arrays? The outer loop iterates over the list of string arrays and sets item as a string array within the list. The inner loop iterates over the string array and sets b as the a string within that array.

I think you need to review your book or talk to your teacher regarding falling behind on how foreach works.
Was This Post Helpful? 0
  • +
  • -

#5 Realme   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 147
  • Joined: 22-May 19

Re: List string array access

Posted 15 June 2019 - 10:44 PM

Can you give finished code I can practice on?
Was This Post Helpful? -4
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,463
  • Joined: 12-June 08

Re: List string array access

Posted 16 June 2019 - 08:41 AM

Quote

Can you give finished code I can practice on?

Please review the rules about asking folk to do your work for you.
Was This Post Helpful? 0
  • +
  • -

#7 Realme   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 147
  • Joined: 22-May 19

Re: List string array access

Posted 16 June 2019 - 08:44 AM

Whatever it is easy anyway, I just needed to delete the Vlista from Richtextbox. Only add b instead
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,463
  • Joined: 12-June 08

Re: List string array access

Posted 16 June 2019 - 08:45 AM

Okey dokey, then I guess you can go ahead and do that without having someone else write it for you. :^:
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6794
  • View blog
  • Posts: 31,354
  • Joined: 10-May 07

Re: List string array access

Posted 16 June 2019 - 02:10 PM

View PostRealme, on 16 June 2019 - 01:44 AM, said:

Can you give finished code I can practice on?

Oh, is mr 150 IQ having a difficult time?
Was This Post Helpful? 0
  • +
  • -

#10 Realme   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 147
  • Joined: 22-May 19

Re: List string array access

Posted 16 June 2019 - 02:18 PM

No pencil, I am not even adding this to my tasks. I am curious because I want to know what I do wrong but I know the answer long ago
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6968
  • View blog
  • Posts: 23,684
  • Joined: 05-May 12

Re: List string array access

Posted 16 June 2019 - 04:44 PM

If you knew the answer long ago, then why are you asking for code showing how to do it?
Was This Post Helpful? 0
  • +
  • -

#12 Realme   User is offline

  • D.I.C Head

Reputation: -9
  • View blog
  • Posts: 147
  • Joined: 22-May 19

Re: List string array access

Posted 17 June 2019 - 03:42 AM

Skydiver,

1. I am studying distance course
2. I am studying what is being taught in one year in one month
3. I study without book.
Was This Post Helpful? 0
  • +
  • -

#13 h4nnib4l   User is offline

  • The Noid
  • member icon

Reputation: 1399
  • View blog
  • Posts: 1,989
  • Joined: 24-August 11

Re: List string array access

Posted 17 June 2019 - 07:10 AM

So does that mean you're only going to be asking us to write code for you for a few more weeks?

Watching these conversations is like reading transcripts from conversations with Donald Trump. The responses never answer the questions, and they all find a way to brag about how smart he is without ever sounding smart.
Was This Post Helpful? 1
  • +
  • -

#14 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6794
  • View blog
  • Posts: 31,354
  • Joined: 10-May 07

Re: List string array access

Posted 17 June 2019 - 07:14 AM

View Posth4nnib4l, on 17 June 2019 - 10:10 AM, said:

So does that mean you're only going to be asking us to write code for you for a few more weeks?


no ;) He won't be asking anymore.

** Closing topic **
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1