Appending a String to All Strings in a List<String>

by fwhagen Wed, 13 June 2012

This is one of those great 1 liners in C# that I can never remember how to do.  If you want to add a value to every string in a List<String>, you can use LINQ to easily utilize String.Format() (or String.Concat()) to do so.  Given a List<String> paths:

paths = (from p in paths select String.Format(@"{0}\badfiles\", p)).ToList<String>();

Keywords:

Filed Under: .NET

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

TextBox

RecentPosts