dimanche 2 mai 2021

"Object Reference is required for non-static field"

So I needed to make a random number generator for my minesweeper project, and I decided to put it in a method.

public static void GenerateBombs(int gsize, int numbombs, HashSet<int> numbers)
    {
        int num = gsize * gsize;
        while (numbers.Count < numbombs)
        {
            numbers.Add(Random.Next(1, num));
        }
    }

However I keep getting the "Object Reference needed for non-static field, property, or method." I don't know why and I can't figure it out from the other questions.




Aucun commentaire:

Enregistrer un commentaire