Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Convert ArrayList object to comma separated string

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.86k
    Comment on it

    ArrayList is an heterogeneous collection of objects where each object can be indexed individually. While writing an application there could be some scenarios where we have ArrayList object filled with data and we want that data in delimited format using any character (comma in our case). For instance suppose we have multiple email addresses added in ArrayList object and we want to use these email addresses in comma separated form so we can set them to To, Cc and Bcc properties in our email component.

     

    Following code snippet shows how to get ArrayList object in comma separated form.

     

    C# Code Sample

    using System;
    using System.Collections;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                ArrayList arrayList = new ArrayList();
                
                arrayList.Add("person1@domain.com");
                arrayList.Add("person2@domain.com");
                arrayList.Add("person3@domain.com");
    
                string commString = String.Join(",", arrayList.ToArray());
    
                Console.Write("Comma separated string = " + commString);
                Console.ReadKey();
            }
        }
    }
    

     

    VB Code Sample

    Module Module1
    
        Sub Main()
            Dim arrayList As New ArrayList()
    
            arrayList.Add("person1@domain.com")
            arrayList.Add("person2@domain.com")
            arrayList.Add("person3@domain.com")
    
            Dim commString As String = [String].Join(",", arrayList.ToArray())
    
            Console.Write(Convert.ToString("Comma separated string = ") & commString)
            Console.ReadKey()
        End Sub
    
    End Module
    

     

    Please note you can use other separator in place of comma(",") to separate the strings.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: