我想從一個方法返回一個隨機數,但顯然隱式類型不正確。它說: 「無法隱式轉換類型 'Randomize.RandomNumber' 到 '廉政'」返回一個隨機數類型問題
RandomNumber.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Randomizer
{
class RandomNumber
{
public int RandomInRange(int l, int u)
{
Random generator = new Random();
return generator.Next(l, u);
}
}
}
的Program.cs:
using System;
using System.Collections.Generic;
using System.Text;
namespace Randomizer
{
class Program
{
static void Main(string[] args)
{
Console.Out.WriteLine("Please enter the minimum range for the random number\n");
int min = int.Parse(Console.In.ReadLine());
Console.Out.WriteLine("Please enter the maximum range for the random number\n");
int max = int.Parse(Console.In.ReadLine());
int RandomInt = new RandomNumber();
Console.Out.WriteLine("Your random number is: " + RandomInt.RandomInRange(min, max));
Console.In.ReadLine();
}
}
}
我知道這幾乎是一個小白問題,但我習慣C++。我在這裏先向您的幫助表示感謝。 =]
啊,現在有道理。謝謝您的幫助! – Stradigos 2010-03-03 00:16:36