एग्रीगेट () मेथड एक एक्युमुलेटर फंक्शन को एक सीक्वेंस पर लागू करता है।
निम्नलिखित हमारी सरणी है -
string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"}; अब एग्रीगेट () विधि का उपयोग करें। हमने तुलना के लिए ssed मान को "DemoFive" के रूप में सेट किया है।
string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest,str => str.ToLower()); यहां, परिणामी स्ट्रिंग में प्रारंभिक बीज मान यानी "DemoFive" की तुलना में वर्णों की संख्या अधिक होनी चाहिए।
उदाहरण
using System;
using System.Linq;
class Demo {
static void Main() {
string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"};
string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest,str => str.ToLower());
Console.WriteLine("The string with more number of characters: {0}", res);
}
} आउटपुट
The string with more number of characters: demothree