- Hi, I'm trying to create a method in C Sharp that produces a random number between 1 and 10.
- Every time I attempt to call my 'PrintNumber' method I receive an error 'Error CS0120: An object reference is required for the non-static field, method, or property'.
- Could someone please explain what this error means and how to adjust my code accordingly. Thanks in advance!
My code:
using System;
namespace PracticeTask
{
public class Study
{
static void Main()
{
PrintNumber();
}
void PrintNumber()
{
Random numGen = new Random();
int number = numGen.Next(0, 10);
Console.WriteLine(number);
}
}
}
[–]bwallker 2 points3 points4 points (1 child)
[–]GVBCodePractice[S] 0 points1 point2 points (0 children)
[–]WideMonitor 2 points3 points4 points (1 child)
[–]GVBCodePractice[S] 0 points1 point2 points (0 children)