0

I have another question and I can't seem to find anything on Google.

What this program does
This program displays the information from an RSS feed.

Question
How can I load all the items from an Arraylist to a TextBox?

Things I have tried
This is what I have so far:

List<Array> list1 = new List<Array>();

foreach (var item in list1)
        {
            textBox1.AppendText(item.ToString());
        }

Problem
When I do this, the TextBox shows this:

System.String[]System.String[]

Instead of:

Recommended Build for CraftBukkit: 1.2.4-R1.0 (build 2126) http://dl.bukkit.org/downloads/craftbukkit/view/00993_1.2.4-R1.0/

Does anybody have any idea how this array stuff work?
Do I need to loop through the array and search for specific indexes?

Sorry, but I'm still a little bit new to C#, and sorry for my English I'm Dutch :<.

2
  • Oh yea sorry, this is how I define the list: List<Array> list1 = new List<Array>(); Commented Apr 4, 2012 at 8:51
  • seems item type is string[], so what you can do is string.Join(',', item) Commented Apr 4, 2012 at 8:51

5 Answers 5

2

It looks like you ArrayList contains array of string instead of string. So try this :

foreach (var item in list1.OfType<string[]>().SelectMany(i => i))
{
    textBox1.AppendText(item);
}
Sign up to request clarification or add additional context in comments.

4 Comments

for what .SelectMany(i => i) ?
@Manitra Andriamitondra This seems to work perfectly :)! Thank you! EDIT: I can't accept the answer yet, need to wait another 7 minutes ):.
SelectMany() converts a list of list to a flat list
There must be something alike Concat or All for it. (I'm not really sure but I think so)
0

It seems that item is a string array, so try to implode it:

foreach (var item in list1)
{
    textBox1.AppendText(string.Join("", item));
}

Comments

0

Your code is basically a list of array. That's why it is showing system.string[]

Change it to

foreach (var item in list1)
{
    textBox1.AppendText(string.Join("", item));
}

It will join your each string[] (i.e. item) in List<> and create it like

firstarrrayfirstitem, firstarrayseconditem

and textbox as

firstarrrayfirstitem, firstarrayseconditem, secondarrayfirstitem, secondarrayseconditem.... and so on.

Comments

0

A better way could be to use a stringbuider for better performance and reduction in a propertychanged event called by the textbox;

System.Text.StringBuilder sb = new System.Text.StringBuilder();

foreach (var item in list1.OfType<string[]>().SelectMany(i => i))
{
    sb.Append(item);
}

textBox1.Text = sb.ToString();

Comments

0

Better way:

textBox1.Text = string.Join("", list1.OfType<string[]>().SelectMany(i => i));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.