嘿我想将一个全局变量传递给一个方法,并在while循环中多次调用它。它接缝不工作,我不知道这是什么问题。它看起来应该来自我看过的一些例子,但显然不是。我想要做的是让体面变量增加到250,我测试了while循环之外的功能[并且它在那里对我有效,但是在它内部,它并不是很多,而是每次都在降低高度时保持0它通过while循环。感谢您与此将变量传递给方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Every measuerments are in
//Feet
//Seconds
//This program is to sim a simple jump with no graphics. Work the numbers out for final implementaion .
namespace Jumper1Test
{
class Program
{
//10 - 20 feet above ground pull both cords to slow down to about 0 ft per second
private static int alt; //in feet 30,000 20,000, 15,000 ft *Note keep decent same scale\measurment
private static float decent = 0; //speed of jumper 250ft per second cute deploed 15-20ft p[er second want to hit 0 when landing
private static int cuteDelay = 3; //3 second cute delay after opeing (ruf estimate on average)
private static bool leftCord;
private static bool rightCord;
private static bool cuteDeployed; //if parachute is deployed
private static bool jumped; //jump iniciated
//environtmnet effects
private enum windDrection {North, South, East, West, NE, NW, SE, SW } //NE NW = North East West respectivly
private static int windspeed; //in knots
static void Main(string[] args)
{
Console.WriteLine("Jump Sim 1.0");
//select the hight for the jump
Console.WriteLine("Enter Jump Altitued:");
Console.WriteLine("a for 30000 Ft");
Console.WriteLine("b for 25000 Ft");
Console.WriteLine("c for 15000 Ft");
String alt1 = Console.ReadLine();
if (alt1.Equals("a"))
{
alt = 30000;
}
else if (alt1.Equals("b"))
{
alt = 25000;
}else { alt = 15000; }
Console.WriteLine("The Hight of the jump is " + alt);
//jumping
int countdown = 5;
while (countdown != 0)
{
Console.WriteLine("Jumping in " + countdown);
System.Threading.Thread.Sleep(1000); //wait for 1 secod.
countdown--;
}
Console.WriteLine("Jump!");
while (alt != 0)
{
alt = alt - 5000;
Console.WriteLine("Altitue = " + alt);
velocity(decent);
Console.WriteLine("Speed is: " + decent);
}
// keep screen from going away
// when run from VS.NET
Console.ReadLine();
}
private static float velocity(float decent)
{
for (int i = 0; i < 8; i++) //its takes 8 seconds to reach terminal velocity
{
decent = decent + 31.25f; //increease speed of fall
System.Threading.Thread.Sleep(1000); //wait for 1 secod.
}
return decent;
}//end of velocity
}
}
我没有看到任何问号。 – 2012-02-15 23:38:45
你是如何“尝试将全局变量传递给方法”而全局变量*在C#中根本不存在? – Krizz 2012-02-15 23:38:49
您不会将'velocity'方法的返回值分配给一个变量。您传递给方法的变量不能在方法内部更改,因为它是一个值类型。 – adrianbanks 2012-02-15 23:38:56