By Alejandro Villarreal
A few months ago we developed a slightly complex service that made use of query notifications to keep an in-memory copy of some database tables. The service worked like a charm, it passed QA, UAT, and went into production, where it has been working ever since. Recently, however, our client had a vague suspicion that something weird was happening with it, but could not pinpoint exactly what, and they only felt like this after a couple of weeks of the service working just fine. Restarting the service dissipated whatever problem the service appeared to be having, so we all lived with that for a while… until they found actual evidence that the service was not respondi...
By Osvaldo Orozco
This is the basic code that you can find when someone converts from an IEnumerable to a CSV string. This will be our starting point.
StringBuilder strBuild = new StringBuilder(1024);
foreach (var item in myList)
{
strBuild.AppendFormat("{0},", item.Key);
}
if (strBuild.Length > 0)
strBuild = strBuild.Remove(result.Length - 1, 1);
string result = strBuild.ToString();
Now, we are going to use the “Aggregate” LINQ function to create the CSV string.
First we need to add the namespace.
using System.Linq;
The Aggregate function has several overloaded methods.
The first method:
TSource Aggregate<TSo...