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:
Flowchart:
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.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework