What the Aggregate method lets you do is basically stitch together an array (or other collection) of strings. You provide a function that tells the Aggregate method how to combine the individual elements. We usually provide this method in the form of a Lambda expression.
Here's an example:
- string strTemp2="\\Taxonomy\\Information Technology\\Router";
- string[] Temp4 = strTemp2.Split(new char[] { '\\'});
- string res=Temp4.Aggregate((prev,cur)=>prev + " , " + cur); [Acting as opposite of split(),created a CSV of strings]
Another overload can be used like this:
- var values = new[] { 10, 20, 30, 40 };
- var result = values.Aggregate(5, (a, b) => a * b);
- Console.WriteLine(result); //Output 1200000 ((((5*10)*20)*30)*40)

Join the conversation! Your thoughts help the community grow.