LINQ Sum() विधि का उपयोग करके तत्वों का योग ज्ञात करें।
उदाहरण
यहाँ पूर्णांक तत्वों के साथ हमारी सूची है:
List<int> list = new List<int> { 99, 34, 77, 75, 87, 35, 88 };
अब Sum() विधि का उपयोग करके योग ज्ञात करें:
list.AsQueryable().Sum();
पूर्ण कोड
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> list = new List<int> { 99, 34, 77, 75, 87, 35, 88 };
int res = list.AsQueryable().Sum();
Console.WriteLine("योग = {0}", res);
}
}
आउटपुट
योग = 495