Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Example1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Populates the 'values' list
  14.             for (int i = 0; i < 10; i++)
  15.                 values.Add(i);
  16.  
  17.             Sum(values);
  18.  
  19.             Console.WriteLine(totalValue);
  20.  
  21.         }
  22.  
  23.         static List<double> values = new List<double>();
  24.  
  25.         static double totalValue = 0;
  26.  
  27.         static void Sum(List<double> LValues)
  28.         {
  29.             double sum = 0;
  30.  
  31.             foreach(double d in values)
  32.             {
  33.                 sum += d;
  34.             }
  35.  
  36.             totalValue = sum;
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement