Advertisement
callumbinner22

pg347 Task 4 complete

Dec 6th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 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 ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.        
  14.             int[] myarray = { 1, 4, 5, 6, 5, 8, 5, 6 };
  15.             Console.WriteLine(Count(myarray, 5));
  16.  
  17.  
  18.         }
  19.         static int Count(int[] numbers, int x)
  20.         {
  21.             if (numbers == null || numbers.Length == 0)
  22.             {
  23.                 return 0;
  24.             }
  25.  
  26.             int count = 0;
  27.             foreach (var item in numbers)
  28.             {
  29.                 if (x.Equals(item))
  30.                 {
  31.                     count++;
  32.                 }
  33.             }
  34.  
  35.             return count;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement