C# Corner

C# Corner

  • Tech Writer
  • 8
  • 1.4k

how to declare a method

Dec 15 2018 5:54 PM
write a method called GetOddEvenSumDifference that takes an array of integers and returns the sum of all the even numbers minus the sum of all the odd numbers.
(e.g. an array containing 6, -2, 3, 5, 8 will return 4, which is (6 + -2 + 8) - (3 + 5).
 
using System;

namespace HelloWorld
{
class Program
{

static void Main(string[] args)
{
int[] numbers = {6, -2, 3, 5, 8};

int result = GetOddEvenSumDifference(numbers);

Console.WriteLine(result);
}
}

Answers (1)