我想從Main()方法內部調用一個GetInputstring方法的值,然後繼續下一步。 我被卡在問候如何可以得到價值myInt和移動。從Main()函數內的方法調用值
myInt(其中它有兩個* around)在Main()中是它獲取錯誤的地方。
static void Main(string[] args)
{
GetInputstring(**myInt**);
if (**myInt** <= 0)
{
Write1(**myInt**);
}
else
{
Write2(**myInt**);
}
Console.ReadKey();
}
public int GetInputstring(int myInt)
{
string myInput;
//int myInt;
Console.Write("Please enter a number: ");
myInput = Console.ReadLine();
myInt = Int32.Parse(myInput);
return myInt;
}
static void Write1(int myInt)
{
while (myInt <= 0)
{
Console.WriteLine("{0}", myInt++);
}
}
static void Write2(int myInt)
{
while (myInt >= 0)
{
Console.WriteLine("{0}", myInt--);
}
}
MyInt是您的參數(您傳遞給您的方法的值)並且未初始化。此外,你不趕上你的返回值(這應該是myInt) –
http://csharp-station.com/Tutorial/CSharp/ –