Is it possible to write the following \'foreach\' as a LINQ statement, and I guess the more general question can any for loop be replaced by a LINQ statement.
I\'m not i
The specific loop in your question can be done declaratively like this:
var result = ListOfResources
.Select(r => r.Id.ToString())
.Aggregate(new StringBuilder(), (sb, s) => sb.Append(sb.Length > 0 ? ", " : String.Empty).Append(s))
.ToString();
As to performance, you can expect a performance drop but this is acceptable for most applications.