I have just started to learn to program in C# and I have created a very simple program that is suppose to summarize all positive numbers that's inside a int array.
The program looks something like this:
static void Main(string[] args)
{
int[] intArr = new int[5] { 1, 2, 3, -1, 0 };
int result = Sum(intArr);
Console.WriteLine("The total sum of the array is: {0}", result);
Console.ReadKey();
}
public static int Sum(int[] intArr)
{
int sum = 0;
for(int i =0; i < intArr .Length; i++)
{
if(values[i]>0)
{
sum += intArr[i];
}
}
return sum;
}
Is there any way I can make this program any smaller or improve it's logic?