Aggregate string value
In this chapter you will learn:
Aggregate two string values
using System;/*j a va2 s. c o m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
string[] curries = { "abc", "abcd", "ab" };
Console.WriteLine(curries.Aggregate((a, b) => a + " " + b));
}
}
Aggregate to reverse a string
using System;/* j a v a 2 s . c om*/
using System.Collections.Generic;
using System.Linq;
class Program
{
private static string ReverseString(string sentence)
{
List<string> words = new List<string>(sentence.Split(' ').ToList());
return words.Aggregate((a, b) => b + " " + a);
}
static void Main(string[] args)
{
string sentence = "this is a test";
string result = ReverseString(sentence);
Console.WriteLine(result);
}
}
Next chapter...
What you will learn in the next chapter:
- How to use All operator
- All with condition
- Using All to determine whether an array contains only odd numbers
Home » C# Tutorial » Linq Operators