 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to multiply all numbers in the list
Firstly, set the list −
List<int> myList = new List<int> () {    5,    10,    7 }; Now, set the value of a variable to 1 that would help us in multiplying −
int prod = 1;
Loop through and get the product −
foreach(int i in myList) {    prod = prod*i; } The following is the code −
Example
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);    } }  Output
List: 5 10 7 Product: 350
Advertisements
 