CopyPastehas never been so tasty!

Convert String Array to String in C#

by anonymous

  • 0
  • 0
  • 0
113 views

Convert String Array to String in C#

String ArraysString Arrays are used to store more than one string. We create and declare string arrays like that:string[] arr1 = new string[] { "one", "two", "three" };We can also perform many operations on string array like we can sort them as well as can modify them to make it possible that string arrays can store a wide range of items instead of just one.We can modify current array as follow:

arr1[1] = “five”;

arr1[2] = “six”; 

 Conversion of string[] to stringThe following code will show the conversion of string[] elements into a simple stringCode 

class Program

    {

 static void Main(string[] args)

        {

 string[] a = {"ALI","UMER","HASSAN"};

Console.WriteLine(Program.StringArrayToString(a));

 Console.ReadLine();

         }

public static string StringArrayToString(object objects)

        {

 string finalString = string.Empty;

string[] stringArray = (string[])objects;

 foreach (string stringElement in stringArray)

            {

finalString += stringElement + "," ;

             }

return finalString;

        }

    }

 

Add A Comment: