Aggregate() मेथड एक संचायक फ़ंक्शन को अनुक्रम पर लागू करता है।
निम्नलिखित हमारी सरणी है:
string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"};अब Aggregate() मेथड का उपयोग करें। हमने तुलना के लिए सीड मान "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("अधिक वर्णों वाली स्ट्रिंग: {0}", res); } }आउटपुट
अधिक वर्णों वाली स्ट्रिंग: demothree