Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of string separate with comma and add prefix string to every item of list

Tags:

string

c#

list

I have list like...

List[0] = "Banana"
List[1] = "Apple"
List[2] = "Orange"

I want to produce output as "My-Banana,My-Apple,My-Orange" for that I'm using the following code:

string AnyName = string.Join(",", Prefix + List));

But not getting the expected output, how to add My- before every item?

like image 209
Faisal Avatar asked Nov 24 '17 05:11

Faisal


1 Answers

Are you looking for something like this Example:

listInput[0] = "Apple";
listInput[1] = "Banana";
listInput[2] = "Orange";
string Prefix = "My-";         
string strOutput = string.Join(",", listInput.Select(x=> Prefix + x));
Console.WriteLine(strOutput);

And you will get the output as My-Apple,My-Banana,My-Orange

like image 125
sujith karivelil Avatar answered Sep 28 '22 08:09

sujith karivelil