Reputation: 13444
I have List consists of {"a","b","c"}
i have string s contains{"alphabets"}
.i like to add the list to string. i need final output in s like this `{"alphabetsabc"}. i like to do this using linq.
Upvotes: 5
Views: 1338
Reputation: 39338
You need the Aggregate method, if you really want to use LINQ.
Upvotes: 1
Reputation: 269648
Using LINQ, or even Join
, would be overkill in this case. Concat
will do the trick nicely:
string s = "alphabets";
var list = new List<string> { "a", "b", "c" };
string result = s + string.Concat(list);
(Note that if you're not using .NET4 then you'll need to use string.Concat(list.ToArray())
instead. The overload of Concat
that takes an IEnumerable<T>
doesn't exist in earlier versions.)
Upvotes: 8
Reputation: 3616
Quick & dirty:
List<string> list = new List<string>() {"a", "b", "c"};
string s = "alphabets";
string output = s + string.Join("", list.ToArray());
Upvotes: 2