सबसे पहले एक अनुक्रम सेट करें:
List<int> myList = new List<int> { 1, 2, 3, 4, 5 };
अब Queryable Sum() विधि का उपयोग करके योग ज्ञात करें:
myList.AsQueryable().Sum();
पूर्ण उदाहरण
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> myList = new List<int> { 1, 2, 3, 4, 5 };
Console.WriteLine("सूची में तत्वों का योग...");
foreach (int res in myList) {
Console.WriteLine(res);
}
int sum = myList.AsQueryable().Sum();
Console.WriteLine("योग = {0}", sum);
}
}
आउटपुट
सूची में तत्वों का योग... 1 2 3 4 5 योग = 15