सबसे पहले, सूची सेट करें -
List<int> myList = new List<int> () {
5,
10,
7
}; अब, एक वेरिएबल का मान 1 पर सेट करें जो हमें गुणा करने में मदद करेगा -
int prod = 1;
लूप करें और उत्पाद प्राप्त करें -
foreach(int i in myList) {
prod = prod*i;
} निम्नलिखित कोड है -
उदाहरण
using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
List<int> myList = new List<int>() {
5,
10,
7
};
Console.WriteLine("List: ");
foreach(int i in myList) {
Console.WriteLine(i);
}
int prod = 1;
foreach(int i in myList) {
prod = prod*i;
}
Console.WriteLine("Product: {0}",prod);
}
} आउटपुट
List: 5 10 7 Product: 350