Populating textbox with contents of Arraylist c#

I have a frustrating problem. With the following code in my clsExchange which is called in my FormExchange with simply txtPhonesInSystem.Text = ClsExchange.listPhones();I can only display the first arraylist entry.

 public string listPhones()
    {
        string strphone = string.Empty;

        foreach (clsPhone phone in phoneArray)
        {

            strphone = (strphone + phone.PhoneNumber.ToString() + "\n");
            return strphone;


        }
        return strphone;
    }

However, if i take the logic and put in in the btn_press event on the form.cs it displays the complete contents. The only difference I can see is instead of return strphone I use txtbox.Text=strphone. Any suggestions greatly appreciated aS I have been at this all day.

EDIT Thankyou all for your answers. I new it had to be something as simple as that. I guess my brain isn't made right for this stuff. Shame because I love it.

Answers


This line inside the foreach is the problem:

return strphone;

You're quitting on the first record.

As an aside, is this still C# 1.0? If not, why are you using ArrayLists?


Need Your Help

Change base href in PHP included file

php html header

I have a header file which has the html <head> tag in it. I'm trying to set the <base href="/mysite/"> in this file, but when I include it (such as into my index.php file), it doesn't

'Permission Denied' when getting images on S3 from Grails

grails groovy amazon-web-services amazon-s3 elastic-beanstalk

I have a grails 2.1.1 app that is accessing images stored in a bucket on s3, which I am accessing using the Grails-AWS plugin.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.