locked
How to get concatenated output of an array list? RRS feed

  • Question

  • User-118859203 posted

    Hi guys,

    My array list is like this: 

    ArrayList arrayList = new ArrayList() { 1, "abc", 33.5M };

    How can I get concatenated output of each object? Thanks.
    Wednesday, December 5, 2018 1:31 AM

Answers

  • User-552477072 posted

    Hi.

    You can do by:

        StringBuilder a = new StringBuilder();
        foreach (object obj in arrayList) a.Append(obj);
        string str = a.ToString();

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2018 2:17 AM

All replies

  • User-552477072 posted

    Hi.

    You can do by:

        StringBuilder a = new StringBuilder();
        foreach (object obj in arrayList) a.Append(obj);
        string str = a.ToString();

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2018 2:17 AM
  • User1520731567 posted

    Hi kamalhussain,

    According to your requirement,you could also use String.Join to concatenate array list.

    For example:

    ArrayList arrayList = new ArrayList() { 1, "abc", 33.5M };
    
    var list = String.Join("", arrayList.ToArray());

    How it works:

    Best Regards.

    Yuki Tao

    Friday, January 4, 2019 8:05 AM