-2

I tried like below

public int[] GetCompletedCalls()
        {
           int[] minMax = int[2];
           minMax[0] = countCompleted;
           minMax[1] = countPendings;
           return minMax;
        }

But at declaring an array variable throwing an error: Invalid expression term 'int'

abbas arman
  • 145
  • 1
  • 13

2 Answers2

5

you need to use the new keyword:

int[] minMax = new int[2];
apomene
  • 14,282
  • 9
  • 46
  • 72
1

There are multiple ways to achieve this. The easiest one needs only a single correction:

int[] minMax = int[2];

should be

int[] minMax = new int[2];

Another opportunity is to do this:

return new [] { countCompleted, countPendings};

or also this:

public void GetCompletedCalls(out int completed, out int pending)
{
    completed = countCompleted;
    pending = countPendings;
}

or also this which uses a Tuple instead (requires C#7):

public (int, int) GetCompletedCalls()
{
    return (countCompleted, countPendings);
}
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
  • More return multiple values options: custom type (class or struct) and old [`Tuple`](https://learn.microsoft.com/en-us/dotnet/api/system.tuple-2?view=netframework-4.7.2). – Sinatr Jan 03 '19 at 12:38