Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using one variable to input 5 integers C#

Tags:

c#

integer

I am using C# and i am trying to find the the average of 5 values but i can only use 2 variables.

How can you input 5 integers into one variable and display the average of said integers

like image 593
Callum97 Avatar asked Aug 31 '15 09:08

Callum97


1 Answers

You can use List like this:

var list = new List<int>(){ 1, 2, 3, 4, 5 };
var average = list.Average();

using Average you'll get average of all values in list

Here you have all functions of Enumerable, you can for e.g. sum all values with Sum

like image 67
Kamil Budziewski Avatar answered Oct 11 '22 03:10

Kamil Budziewski