Re: random number generator help



"Mike Langworthy" <mcl1982@xxxxxxxxxxx> wrote in message news:ev$sEzIiHHA.1240@xxxxxxxxxxxxxxxxxxxxxxx
i can not seem to get this code to work. someone please help

You are calling an instance method from a static method. It will work if you add the keyword "static" to the instance method:


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int returnValue = RandomNumber(5, 20);
Console.Write(returnValue);
}
private static int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
}
}

.



Relevant Pages

  • Re: static methods
    ... An instance method has no meaning to the class itself. ... Note, though, that since the method square() never references ... private int number; ... public Number(int num) ...
    (comp.lang.java.programmer)
  • Re: MethodType in python 2.2
    ... cannot create 'instance method' instances ... In 2.2, *some* type objects, like int, were turned into callable ... contructors as part of the introduction of new-type classes. ... When the experiment proved to be a success, additional type objects were ...
    (comp.lang.python)
  • Re: current type in static methods
    ... >> because using GetTypeor class has a different meaning, ... >> instance method is useful too ... the first option alters the meaning of the "this" ... keyword which is not good. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Help -- New to Java
    ... You'll need a method name that isn't a keyword. ... public static int mean{ ... This could just as well be an instance method. ... /// Bjorn A ...
    (comp.lang.java.help)