Converting Array to String and Vice Versa using C#

In this Blog we are going to see. How to Convert ARRAY to String and Viceversa using C#

Used Namespace:

using System; 

Code Snippet:

/// <summary>

        /// This Converts Array to String and Vice Versa

        /// </summary>

        public void ConvertingStringToArray()

        {

            //Declare Array

            string[] array = { "Lajapathy", "Arun" };

 

            Console.WriteLine("Array Items");

            //Displaying the Array Value.

            foreach (string s in array)

            {

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(s);

            }

 

            //Converts Array to String

            string arrayJoin = string.Join(" ", array);

 

            Console.WriteLine("Joined Array :" + arrayJoin);

 

            string[] convertStringToArray = arrayJoin.Split(' ');

 

            //Displaying the Array Value.

            foreach (string s in convertStringToArray)

            {

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine(s);

            }

        }

 

OUTPUT:

Lajapathy

Arun

Joined Array: Lajapathy Arun

Lajapathy

Arun