我已经在C#编写了大约3年的编码,但刚刚开始走出我的舒适区。我正在尝试开发一个用于设计基本过山车的计算器,但是在我尝试第一部分之后,我遇到了抛出并终止我的程序的stackoverflowexception。我发现的变量是麻烦的时间"时间"全局类变量和" Velocity"全局类变量。我总是试图在我的代码的主菜单上按下选项编号1(升降机山坡),然后进行数学运算。当我给出最终值以计算该部分的解决方案时,它会抛出异常。我不知道它是变量的初始化还是调用类方法的过程。我的代码发布在下面,感谢您的帮助。
namespace ConsoleApplication3
{
public static class Global
{
public static double Velocity
{
get { return Velocity; }
set { Velocity = value; }
}
public static double Time
{
get { return Time; }
set { Time = value; }
}
public static double MaxVel
{
get { return MaxVel; }
set { MaxVel = value; }
}
public static double MaxAccel
{
get { return MaxAccel; }
set { MaxAccel = value; }
}
public static double MaxPosG
{
get { return MaxPosG; }
set { MaxPosG = value; }
}
public static double MaxNegG
{
get { return MaxNegG; }
set { MaxNegG = value; }
}
public static double MaxLatG
{
get { return MaxLatG; }
set { MaxLatG = value; }
}
}
class Program
{
static void Main(string[] args)
{
double Straight_Time = 0, Brake_Time = 0, D_Time = 0, U_Time = 0, CurveUp_Time = 0, CurveDwn_Time = 0, UBTurn_Time = 0, BTurn_Time = 0, Helix_Time = 0, Helix_Velocity = 0, Helix_Time1 = 0, Helix_Time2 = 0;
double Loop_Time = 0, arc1_Time = 0, arc2_Time = 0, arc3_Time = 0, Loop_Velocity = 0;
const double M = 248.4472;// Cars Weight
const double Mu = 0.08;//Friction Value
const double G = 32.2;//Acceleration of gravity
const double VelCheck = 146.667;
const double AccelCheck = 100;
const double GCheck_Pos = 5;
const double GCheck_Neg = -1;
const double GCheck_Lat = 10;
double Power = 0;
Console.WriteLine("Roller Coaster Project Calculator");
Console.WriteLine("");
DrawingBoard:
Console.WriteLine("Please Select a Calculation");
Console.WriteLine("");
Console.WriteLine("1) Lift Hill");
Console.WriteLine("2) Hill Downwards");
Console.WriteLine("3) Hill Upward");
Console.WriteLine("4) Hill Upward Curve");
Console.WriteLine("5) Hill Downward Curve");
Console.WriteLine("6) Straight Section");
Console.WriteLine("7) Unbanked Turn");
Console.WriteLine("8) Banked Turn");
Console.WriteLine("9) Brake");
Console.WriteLine("10) Teardrop Loop");
Console.WriteLine("11) Helix");
int x = Convert.ToInt32(Console.ReadLine());
Console.Clear();
switch (x)
{
case 1:
Console.WriteLine("Please Enter The Speed of the Lift Hill in MPH");
double lift_Speed = double.Parse(Console.ReadLine());
double lift_Convert = lift_Speed * 1.46667;
Console.WriteLine("Please Enter The Lift Hill Angle");
double lift_Degree = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter The Lift Hill Height");
double lift_Height = double.Parse(Console.ReadLine());
double lift_Distance = lift_Height / Math.Sin(lift_Degree);
double lift_Time = lift_Distance / lift_Convert;
Global.Time = Global.Time + lift_Time;
Power = ((M * G * lift_Height) / lift_Time);
Global.Velocity = lift_Speed;
break;
case 2: //this is for the downward facing hills
Console.WriteLine("Please Enter The Inital Hill Height");
double D_Height_i = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter The Final Hill Height");
double D_Height_f = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter The Hill Angle");
double D_Angle = double.Parse(Console.ReadLine());
double D_Vel = Math.Sqrt(Math.Pow(Global.Velocity,2) + (2 * G * D_Height_i) + (2 * G * D_Height_f));
double D_Fc = M * G;
double D_DeltaVel = D_Vel - Global.Velocity;
double D_Fn = D_Fc * Math.Acos(D_Angle);
double D_Accel = (D_Fc * Math.Cos(D_Angle))/M;
double D_Ff = Mu * D_Fn;
double D_Deceleration = -(D_Ff / M);
double D_DeltaHeight = D_Height_i - D_Height_f;
double D_Distance = D_DeltaHeight / Math.Sin(D_Angle);
double D_Vel2 = Math.Sqrt((2 * D_Deceleration * D_DeltaHeight) + Math.Pow(D_Vel, 2));
if(VelCheck <= D_Vel2 || AccelCheck <= D_Accel)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if(D_Vel2 > Global.MaxVel)
{
Global.MaxVel = D_Vel2;
}
D_Time = D_DeltaVel / (D_Accel - D_Deceleration);
Global.Velocity = Global.Velocity + D_Vel2;
Global.Time = Global.Time + D_Time;
break;
case 3:
Console.WriteLine("Please Enter The Inital Hill Height");
double U_Height_i = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter The Final Hill Height");
double U_Height_f = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter The Hill Angle");
double U_Angle = double.Parse(Console.ReadLine());
double U_Vel = Math.Sqrt(Math.Pow(Global.Velocity, 2) + (2 * G * U_Height_i) + (2 * G * U_Height_f));
double U_DeltaVel = Global.Velocity - U_Vel;
double U_Fc = M * G;
double U_Fn = U_Fc * Math.Acos(U_Angle);
double U_Accel = (U_Fc * Math.Cos(U_Angle)) / M;
double U_Ff = Mu * U_Fn;
double U_Deceleration = -(U_Ff / M);
double U_DeltaHeight = U_Height_f - U_Height_i;
double U_Distance = U_DeltaHeight / Math.Cos(U_Angle);
double U_Vel2 = Math.Sqrt((2 * U_Deceleration * U_DeltaHeight) + Math.Pow(U_Vel, 2));
if (VelCheck <= U_Vel2 || AccelCheck <= U_Accel)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (U_Vel2 > Global.MaxVel)
{
Global.MaxVel = U_Vel2;
}
U_Time = U_DeltaVel / (U_Accel + U_Deceleration);
Global.Velocity = Global.Velocity + U_Vel2;
Global.Time = Global.Time + U_Time;
break;
case 4:
Console.WriteLine("Please Enter The Hill Angle");
double CurveUp_Angle = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter the Curve Radius");
double CurveUp_Radius = double.Parse(Console.ReadLine());
double CurveUp_Length = CurveUp_Angle * CurveUp_Radius;
double CurveUp_Force = M * Math.Pow(Global.Velocity, 2) / CurveUp_Radius;
double CU_Fn = M * G;
double CU_Ff = Mu * (CU_Fn + CurveUp_Force);
double CU_G = ((CU_Fn + CurveUp_Force) / M) * 0.03107033639; //converts to G's
double CurveUp_Deceleration = CU_Ff / M;
double CU_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * CurveUp_Deceleration * CurveUp_Length))) / CurveUp_Deceleration;
double CU_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * CurveUp_Deceleration * CurveUp_Length))) / CurveUp_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", CU_Quad1, CU_Quad2);
int u = int.Parse(Console.ReadLine());
switch (u)
{
case 1:
CurveUp_Time = CU_Quad1;
break;
case 2:
CurveUp_Time = CU_Quad2;
break;
}
double CU_Vel = Global.Velocity + (CurveUp_Deceleration * CurveUp_Time);
if (GCheck_Pos <= CU_G)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if(CU_Vel > Global.MaxVel)
{
Global.MaxVel = CU_Vel;
}
if (CU_G > Global.MaxPosG)
{
Global.MaxPosG = CU_G;
}
Global.Time = Global.Time + CurveUp_Time;
Global.Velocity = Global.Velocity + (CurveUp_Deceleration * CurveUp_Time);
break; case 5:
Console.WriteLine("Please Enter The Hill Angle");
double CurveDwn_Angle = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter the Curve Radius");
double CurveDwn_Radius = double.Parse(Console.ReadLine());
double CurveDwn_Length = CurveDwn_Angle * CurveDwn_Radius;
double CurveDwn_Force = M * Math.Pow(Global.Velocity, 2) / CurveDwn_Radius;
double CD_Fn = M * G;
double CD_Ff = Mu * (CD_Fn - CurveDwn_Force);
double CD_G = ((CD_Fn - CurveDwn_Force) / M) * 0.03107033639; //converts to G's
double CurveDwn_Deceleration = CD_Ff / M;
double CD_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * CurveDwn_Deceleration * CurveDwn_Length))) / CurveDwn_Deceleration;
double CD_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * CurveDwn_Deceleration * CurveDwn_Length))) / CurveDwn_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", CD_Quad1, CD_Quad2);
int d = int.Parse(Console.ReadLine());
switch (d)
{
case 1:
CurveDwn_Time = CD_Quad1;
break;
case 2:
CurveDwn_Time = CD_Quad2;
break;
}
double CD_Vel = Global.Velocity + (CurveDwn_Deceleration * CurveUp_Time);
if (GCheck_Neg >= CD_G)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (CD_Vel > Global.MaxVel)
{
Global.MaxVel = CD_Vel;
}
if (CD_G < Global.MaxNegG)
{
Global.MaxNegG = CD_G;
}
Global.Time = Global.Time + CurveDwn_Time;
Global.Velocity = Global.Velocity + (CurveDwn_Deceleration * CurveDwn_Time);
break;
case 6:
Console.WriteLine("Please Enter the Length of the Straight Away");
double Straight_Distance = double.Parse(Console.ReadLine());
double Straight_Force = M * G;
double Straight_Friction = -(Mu * Straight_Force);
double Straight_Deceleration = Straight_Friction / M;
double S_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity,2) - (2 * Straight_Deceleration * Straight_Distance)))/Straight_Deceleration;
double S_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * Straight_Deceleration * Straight_Distance))) / Straight_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", S_Quad1, S_Quad2);
int y = int.Parse(Console.ReadLine());
switch (y)
{
case 1:
Straight_Time = S_Quad1;
break;
case 2:
Straight_Time = S_Quad2;
break;
}
Global.Time = Global.Time + Straight_Time;
Global.Velocity = Global.Velocity + (Straight_Deceleration * Straight_Time);
break;
case 7:
Console.WriteLine("What is The Angle of the turn?");
double UBTurn_Angle = double.Parse(Console.ReadLine());
double UBTurn_Theta = double.Parse(Console.ReadLine());
Console.WriteLine("What is the Radius of the turn?");
double UBTurn_Radius = double.Parse(Console.ReadLine());
double UBTurn_Length = UBTurn_Theta * UBTurn_Radius;
double UBTurn_Force = M * G;
double UBTurn_Friction = -(Mu * UBTurn_Force);
double UBTurn_Deceleration = UBTurn_Friction / M;
double UBT_G = (UBTurn_Friction / M) *0.03107033639; //converts to G's
double UBT_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * UBTurn_Deceleration * UBTurn_Length))) / UBTurn_Deceleration;
double UBT_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * UBTurn_Deceleration * UBTurn_Length))) / UBTurn_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", UBT_Quad1, UBT_Quad2);
int a = int.Parse(Console.ReadLine());
switch (a)
{
case 1:
UBTurn_Time = UBT_Quad1;
break;
case 2:
UBTurn_Time = UBT_Quad2;
break;
}
if (GCheck_Lat >= UBT_G)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (UBT_G < Global.MaxLatG)
{
Global.MaxLatG = UBT_G;
}
Global.Time = Global.Time + UBTurn_Time;
Global.Velocity = Global.Velocity + (UBTurn_Deceleration * UBTurn_Time);
break;
case 8:
Console.WriteLine("What is The Angle of the turn?");
double BTurn_Angle = double.Parse(Console.ReadLine());
double BTurn_Theta = double.Parse(Console.ReadLine());
Console.WriteLine("What is the Radius of the turn?");
double BTurn_Radius = double.Parse(Console.ReadLine());
Console.WriteLine("What is the Bank of the turn?");
double BTurn_Bank = double.Parse(Console.ReadLine());
double BTurn_Length = BTurn_Theta * BTurn_Radius;
double BTurn_Force = ((Math.Tan(BTurn_Bank) + Mu)/(1 - (Mu * Math.Tan(BTurn_Bank)))) * M * G;
double BT_G = (BTurn_Force / M) * 0.03107033639; //converts to G's
double BTurn_Friction = -(Mu * BTurn_Force);
double BTurn_Deceleration = BTurn_Friction / M;
double BT_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * BTurn_Deceleration * BTurn_Length))) / BTurn_Deceleration;
double BT_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * BTurn_Deceleration * BTurn_Length))) / BTurn_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", BT_Quad1, BT_Quad2);
int b = int.Parse(Console.ReadLine());
switch (b)
{
case 1:
BTurn_Time = BT_Quad1;
break;
case 2:
BTurn_Time = BT_Quad2;
break;
}
double BTurn_Vel = Global.Velocity + (BTurn_Deceleration * BTurn_Time);
if (GCheck_Pos <= BT_G)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (BTurn_Vel > Global.MaxVel)
{
Global.MaxVel = BTurn_Vel;
}
if (BT_G > Global.MaxPosG)
{
Global.MaxPosG = BT_G;
}
Global.Time = Global.Time + BTurn_Time;
Global.Velocity = Global.Velocity + (BTurn_Deceleration * BTurn_Time);
break;
case 9:
double Brake_Final = 10;//ft/s
double Brake_Mu = 0.91;
double Brake_Force = M * G;
double Brake_Friction = -(Brake_Mu * Brake_Force);
double Brake_Deceleration = Brake_Friction / M;
double Brake_Distance = (Math.Pow(Brake_Final,2) - Math.Pow(Global.Velocity,2))/(2 * Brake_Deceleration);
double B_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * Brake_Deceleration * Brake_Distance))) / Brake_Deceleration;
double B_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * Brake_Deceleration * Brake_Distance))) / Brake_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", B_Quad1, B_Quad2);
int z = int.Parse(Console.ReadLine());
switch (z)
{
case 1:
Brake_Time = B_Quad1;
break;
case 2:
Brake_Time = B_Quad2;
break;
}
Global.Time = Global.Time + Brake_Time;
Console.WriteLine("The Final Braking Speed Running into the Station is 10 ft/s");
Console.WriteLine("The Brake Distance is {0}", Brake_Distance);
break;
case 10:
Console.WriteLine("Please Enter The Outer Radii");
double outer_Loop = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter The Inner Radius");
double inner_Loop = double.Parse(Console.ReadLine());
double loopTheta1 = 90;
double loopTheta2 = 180;
double loopTheta3 = 90;
double arc1 = outer_Loop * loopTheta1;
double arc2 = inner_Loop * loopTheta2;
double arc3 = outer_Loop * loopTheta3;
double arc1_Force = M * Math.Pow(Global.Velocity, 2) / outer_Loop;
double arc1_Fn = M * G;
double arc1_Ff = Mu * (arc1_Fn + arc1_Force);
double arc1_Deceleration = arc1_Ff / M;
double Garc1 = ((arc1_Fn + arc1_Force) / M) * 0.03107033639; //converts to G's
double arc1_Quad1 = (-Global.Velocity + Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * arc1_Deceleration * arc1))) / arc1_Deceleration;
double arc1_Quad2 = (-Global.Velocity - Math.Sqrt(Math.Pow(Global.Velocity, 2) - (2 * arc1_Deceleration * arc1))) / arc1_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", arc1_Quad1, arc1_Quad2);
int l = int.Parse(Console.ReadLine());
switch (l)
{
case 1:
arc1_Time = arc1_Quad1;
break;
case 2:
arc1_Time = arc1_Quad2;
break;
}
if (GCheck_Pos <= Garc1)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (Garc1 > Global.MaxPosG)
{
Global.MaxPosG = Garc1;
}
Loop_Time = Loop_Time + arc1_Time;
Loop_Velocity = Loop_Velocity + (arc1_Deceleration * arc1_Time);
double arc2_Force = M * Math.Pow(Loop_Velocity, 2) / inner_Loop;
double arc2_Fn = M * G;
double arc2_Ff = Mu * (arc2_Fn - arc2_Force);
double arc2_Deceleration = arc2_Ff / M;
double Garc2 = ((arc1_Fn + arc1_Force) / M) * 0.03107033639; //converts to G's
double arc2_Quad1 = (-Loop_Velocity + Math.Sqrt(Math.Pow(Loop_Velocity, 2) - (2 * arc2_Deceleration * arc2))) / arc2_Deceleration;
double arc2_Quad2 = (-Loop_Velocity - Math.Sqrt(Math.Pow(Loop_Velocity, 2) - (2 * arc2_Deceleration * arc2))) / arc2_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", arc2_Quad1, arc2_Quad2);
int m = int.Parse(Console.ReadLine());
switch (m)
{
case 1:
arc2_Time = arc2_Quad1;
break;
case 2:
arc2_Time = arc2_Quad2;
break;
}
if (GCheck_Pos <= Garc2)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (Garc2 > Global.MaxPosG)
{
Global.MaxPosG = Garc2;
}
Loop_Time = Loop_Time + arc2_Time;
Loop_Velocity = Loop_Velocity + (arc2_Deceleration * arc2_Time);
double arc3_Force = M * Math.Pow(Loop_Velocity, 2) / outer_Loop;
double arc3_Fn = M * G;
double arc3_Ff = Mu * (arc3_Fn + arc3_Force);
double arc3_Deceleration = arc3_Ff / M;
double Garc3 = ((arc1_Fn + arc1_Force) / M) * 0.03107033639; //converts to G's
double arc3_Quad1 = (-Loop_Velocity + Math.Sqrt(Math.Pow(Loop_Velocity, 2) - (2 * arc3_Deceleration * arc3))) / arc3_Deceleration;
double arc3_Quad2 = (-Loop_Velocity - Math.Sqrt(Math.Pow(Loop_Velocity, 2) - (2 * arc3_Deceleration * arc3))) / arc3_Deceleration;
Console.WriteLine("Which is the positive number? 1: {0} 2: {1}", arc2_Quad1, arc2_Quad2);
int n = int.Parse(Console.ReadLine());
switch (n)
{
case 1:
arc3_Time = arc3_Quad1;
break;
case 2:
arc3_Time = arc3_Quad2;
break;
}
if (GCheck_Pos <= Garc3)
{
Console.WriteLine("Does not Meet the Saftey Constraints, Please Retry calculation.");
Console.WriteLine("Press Any Button to return to Menu");
Console.ReadKey();
Console.Clear();
goto DrawingBoard;
}
if (Garc3 > Global.MaxPosG)
{
Global.MaxPosG = Garc3;
}
Loop_Time = Loop_Time + arc3_Time;
Loop_Velocity = Loop_Velocity + (arc3_Deceleration * arc3_Time);
Global.Time = Global.Time + Loop_Time;
Global.Velocity = Global.Velocity + Loop_Velocity;
break;
}
Console.WriteLine("The Final Velocity of This Section is {0} Feet Per Section", Global.Velocity);
double Kinetic = (0.5) * M * Math.Pow(Global.Velocity, 2);
Console.WriteLine("The Final Kinetic Energy of This Section is {0} Joules", Kinetic);
Console.WriteLine("");
Console.WriteLine("Would You Like to Continue the Roller Coaster?");
Console.WriteLine("1) Yes");
Console.WriteLine("2) No");
int f = int.Parse(Console.ReadLine());
switch(f)
{
case 1:
Console.Clear();
goto DrawingBoard;
case 2:
goto Final_Menu;
}
Final_Menu:
Console.Clear();
double min_Time = Global.Time / 60;
double Percent = Power - Kinetic;
Console.WriteLine("The Maximum Velocity Was {0}", Global.MaxVel);
Console.WriteLine("The Maximum Acceleration Was {0}", Global.MaxAccel);
Console.WriteLine("The Maximum Positive G's Were {0}", Global.MaxPosG);
Console.WriteLine("The Maximum Negative G's Were {0}", Global.MaxNegG);
Console.WriteLine("The Maximum Lateral G's Were {0}", Global.MaxLatG);
Console.WriteLine("Total Ride Time Length is {0} Seconds or {1} Minutes", Global.Time, min_Time);
Console.WriteLine("The Final Kinetic Energy is {0}, Which is {1}% of the original Amount of Energy", Kinetic, Percent);
Console.WriteLine("");
Console.WriteLine("Please Press Any Button To Exit Program...");
Environment.Exit(0);
}
}
}
答案 0 :(得分:2)
您的属性定义如下:
public static double Velocity
{
get { return Velocity; }
set { Velocity = value; }
}
当此属性为Got或Set时,它引用自身,然后引用自身,然后引用自身 ad infinitum - 或者更确切地说,直到引发堆栈溢出异常。
我想你想要auto-property syntax代替:
public static double Velocity { get; set; }
或者,使用支持字段:
private static double velocity;
public static double Velocity
{
get { return velocity; }
set { velocity = value; }
}