सबसे पहले, एक क्रम सेट करें।
List<int> myList = new List<int> { 1, 2, 3, 4 ,5}; अब क्वेरी करने योग्य योग () विधि का उपयोग करके योग ज्ञात करें।
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("Sum of elements in a list...");
foreach (int res in myList) {
Console.WriteLine(res);
}
int sum = myList.AsQueryable().Sum();
Console.WriteLine("Sum = {0}", sum);
}
} आउटपुट
Sum of elements in a list... 1 2 3 4 5 Sum = 15