

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
- Related Questions & Answers
- Python program to multiply all numbers in the list?
- C++ Program to Multiply two Numbers
- Python Program to Multiply All the Items in a Dictionary
- How to multiply large numbers with all digits in the output in R?
- Java program to multiply given floating point numbers
- 8051 Program to Multiply two 8 Bit numbers
- 8085 Program to Multiply two 8 bits numbers
- 8085 program to multiply two 8 bit numbers
- 8086 program to multiply two 8-bit numbers
- 8086 program to multiply two 16-bit numbers
- C Program to Multiply two Floating Point Numbers?
- Java Program to Multiply Two Floating-Point Numbers
- Golang Program to Print the Sum of all the Positive Numbers and Negative Numbers in a List
- 8085 Program to multiply two 2-digit BCD numbers
- 8085 Program to multiply two 16-bit binary numbers
Advertisements