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.
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.)
Why not just string.Join
? Using Linq would be an overkill.
Quick & dirty:
List<string> list = new List<string>() {"a", "b", "c"};
string s = "alphabets";
string output = s + string.Join("", list.ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With