Seal_of_approval

task2(a)

May 15th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace task2
  5. {
  6.     public static class ArrayExtensios
  7.     {
  8.         public static int SumArray(this int[] a)
  9.         {
  10.             int res = 0;
  11.  
  12.             foreach (int item in a)
  13.                 res += item;
  14.  
  15.             return res;
  16.         }
  17.     }
  18.  
  19.     class Program
  20.     {
  21.         public static void Main (string[] args)
  22.         {
  23.             int[] array = new int[]{ 10, 20, 30, 90, 80, 70 };
  24.             int res = array.SumArray();
  25.  
  26.             Console.WriteLine ("Sum of array's items = {0}", res);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment