Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Convert a string array to a string

C# Sharp LINQ : Exercise-13 with Solution

Write a program in C# Sharp to convert a string array to a string.

Sample Solution:-

C# Sharp Code:

using System;
using System.Linq;
using System.Collections.Generic;
 
class LinqExercise13
{
	static void Main(string[] args)
		{

		    string[] arr1;
		    int n,i;
		    
		    Console.Write("\nLINQ : Convert a string array to a string : "); 
            Console.Write("\n------------------------------------------\n");	
		    Console.Write("Input number of strings to  store in the array :");
		    n= Convert.ToInt32(Console.ReadLine()); 
            arr1=new string[n];      
            Console.Write("Input {0} strings for the array  :\n",n);
                for(i=0;i<n;i++)
                {
                Console.Write("Element[{0}] : ",i);
                arr1[i] = Console.ReadLine();	
                }	

			string newstring = String.Join(", ", arr1
                          .Select(s => s.ToString())
                          .ToArray());
            Console.Write("\nHere is the string below created with elements of the above array  :\n\n");                          
			Console.WriteLine(newstring);      
            Console.Write("\n");
			Console.ReadLine();
		}
}

Sample Output:

LINQ : Convert a string array to a string :                         
------------------------------------------                          
Input number of strings to  store in the array :4                   
Input 4 strings for the array  :                                    
Element[0] : Cat                                                    
Element[1] : Dog                                                    
Element[2] : Cow                                                    
Element[3] : Tiger                                                  
                                                                    
Here is the string below created with elements of the above array  :
                                                                    
Cat, Dog, Cow, Tiger 

Pictorial Presentation:

C# Sharp LINQ: Convert a string array to a string.

Flowchart:

Flowchart: LINQ : Convert a string array to a string

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to find the uppercase words in a string.
Next: Write a program in C# Sharp to find the n-th Maximum grade point achieved by the students from the list of students.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.