Q:

Check if number is unique and then add it to an array. Help to find bug

I am doing an app that uses Random() class and the method that fills the numbers in the array has a bug. It still adds the same values in the array. It is supposed to check if the random generated value is already in the array and if it is not in there to add it. Else it should leave the loop and generate another integer.
Code:
    /*
     * Method to fill in the array with numbers
     */
    public void FillArrayWithRandomNumbers()
    {

        bool unique = false;

        for (int i = 0; i < NrOfWantedNumbers; i++)
        {
            _randomNumber = rndm.Next(1, MaxValue) + 1;
            while (unique == false)
            {
                foreach (var item in storeLottoNum)
                {
                    if (item == _randomNumber)
                        unique = false;
                    else
                    {
                        unique = true;
                    }
                }
            }
            if (unique)
                storeLottoNum[storeNextIndex] = _randomNumber;
                ++storeNextIndex;
                unique = false;
        }  
    }

A:

Your code probably would work if you had added braces. You indented the code under your if statement, but didn't add any braces. This isn't Python.
if (unique == true) // By the way, can be shortened to if (unique)
{ // <-- You were missing this
    storeLottoNum[storeNextIndex] = _randomNumber;
    ++storeNextIndex;
    unique = false;
} // <-- You were missing this too

An easier way to do this though:
unique = !storeLottoNum.Contains(item)

That one line can complete eliminate your while loop and everything in it. This will set your unique variable automatically.

A:

assuming that :

storeLottoNum is type int[];
storeLottoNum has size = NrOfWantedNumbers 
storeNextIndex is initialized with 0

EDIT: Added comments to the code
then try:
  /*
 * Method to fill in the array with numbers
 */
public void FillArrayWithRandomNumbers()
{

     for (int i = 0; i < NrOfWantedNumbers; i++)  // for each number you want
    {
        do
        {
            unique = true;                                     // Assume new value is unique
            _randomNumber = rndm.Next(1, MaxValue) + 1;        // get the random number
            for (int item = 0; item < storeNextIndex; item++)  // Check each element with a value in your array
            {
                if (storeLottoNum[item] == _randomNumber)      // if the value is the same
                {
                    unique = false;       // It is not unique
                    break;                // break the loop, we don't care about the other values
                }
            }
        } while (unique == false);        // if it was not unique, try again

        storeLottoNum[storeNextIndex++] = _randomNumber;   // with unique value, save in the array and increment the 'storeNextIndex'
    } 
}

