Join strings from a List while also formating them The code I have wrote works fine, this inquiry being purely for educational purposes. I want to know how others would do this better and cleaner. I especially hate the way I add the list items to another list before they are joined. There has to be a more efficient way.

I realize an easy way to make this simple would be to store "OU=" and "DC=" in the database with their associated text, but that just feels unseemly to me.

I am building a string for the container argument of the PrincipalContext class for an LDAP call.

The "lst" List&lt;string&gt; contains DataRows of LDAP Organization Units like "Accounts", "Users", etc.

// Get ou list
List&lt;string&gt; lst = db.sda(sql).Rows.OfType&lt;DataRow&gt;().Select(dr =&gt; dr.Field&lt;string&gt;("txt")).ToList();

string OU = string.Empty;
List&lt;string&gt; lst = new List&lt;string&gt;();

foreach (string ou in Web.Info.Ldap.ouList)
{
    lst.Add(string.Format("OU={0}", ou));
}
OU = string.Join(",", lst); 


Result:


  OU=Users,OU=Accounts,OU=Employees


I do the same thing to a list called dcList that produces the same kind of string:

DC = string.Join(",", lst); 


Result:


  DC=severname,DC=another_value,DC=com


to which I join together with OU to get the complete string, like so:

string container = string.Join(",", OU, DC);


End result:


  OU=Users,OU=Accounts,OU=Employees,DC=sever,DC=othervalue,DC=com
String.Join can work with IEnumerable&lt;T&gt; so its not necessary to pass list to it. Same goes for foreach: you do not have to call ToList() at the end of your first query, you can loop through initial enumeration. 
With LINQ you can join strings like that:

//you can call `ToList()` at the end, if you need to cache query results, but you dont have to
var fields = db.sda(sql).Rows.OfType&lt;DataRow&gt;().Select(dr =&gt; dr.Field&lt;string&gt;("txt"));
//you can merge this Select with the previous one, if you are not going to re-use `fields` enumeration
var ou = fields.Select(f =&gt; "OU=" + f);
var dc = someOtherFields.Select(f =&gt; "DC=" + f);

var result = String.Join(",", ou.Concat(dc));