15,963,996 members
See more:
I am trying to make a mastermind game where I having the user guess a number sequence between 4-10 instead of colours but for some reason my GetRandomNumberCount, CountHits get the error Cannot implicitly convert type to int[]

Any guidance would be appreciated

C#
```// This method compares the random numbers to the ones the user has guessed
public static int CountHits(int userGuess, int[] randomNumbers)
{
int correctGuess = 0;

if(userGuess == randomNumbers)
{
Console.WriteLine("Hit");
correctGuess++;
}
else
{
Console.WriteLine("Miss");
}
return correctGuess;
}
```

C#
```// This method gets the quantity of random numbers to use in the game.
public static int GetRandomNumberCount(int difficulty)
{
int[] randomNumber = 0;

if(difficulty == 1)
{
randomNumber= GenerateRandomNumber(0, 4);
}
else if(difficulty == 2)
{
randomNumber = GenerateRandomNumber(1, 6);
}
else if (difficulty == 3)
{
randomNumber = GenerateRandomNumber(1, 11);
}

return randomNumber;

}
// This method generates the random numbers for the array of numbers.
public static int[] GenerateRandomNumber(int min, int max)
{

// this declares an integer array with 5 elements
// and initializes all of them to their default value
// which is zero
int[] test2 = new int[5];

Random randNum = new Random();
for (int i = 0; i < test2.Length; i++)
{
test2[i] = randNum.Next(min, max);
}
return test2;
}
```
Posted
Updated 10-May-19 0:40am
Sergey Alexandrovich Kryukov 15-Jul-15 1:05am
In what line? Isn't the error message crystal clear?
—SA

## Solution 1

Is the error coming perhaps from this row
C#
`int[] randomNumber = 0;`

Should `randomNumber` be a single variable instead of an array ?

v2

## Solution 2

int[] randomNumber = new int[] { };

CHill60 10-May-19 7:09am
That will just move the problem to another place, namely
`return randomNumber;`
And if you fix the function
`public static int[] GetRandomNumberCount(int difficulty)`
that will just move the error to
`if(userGuess == randomNumbers)`