I'm programming in c#. I have written a method to generate random imei, which has 15 numbers from 0 to 9. I combine them using StringBuilder and return the whole code as string.
public static string randomIMEIgenerator()
{
var builder = new StringBuilder();
while (builder.Length < 15)
{
builder.Append(Rnd.Next(10).ToString());
}
return builder.ToString();
}
Now the thing is that I want to run this method x times, because I want to generate x imei codes. Why when I write for loop I get this error?
An object reference is required for the non-static field, method, or property
My main function:
private static readonly Random Rnd = new Random();
int x = 5;
public static void Main(string[] args)
{
for (int i = 0; i < x; i++)
{
randomIMEIgenerator();
}
}
I also want to store all of those randomly generated imei's to an array. Should I just do it like that?
String[] array = new String[x];
for (int i = 0; i < x; i++)
{
array = randomIMEIgenerator();
}
However my main question is about that error.
P.S. If I run this only one time, it generates one imei number. So the method randomIMEIgenerator is working properly.