我是C#的新手,所以对这很简单,我深表歉意。但是我似乎无法调试我的代码。一切对我来说都很好。太混乱了我更喜欢python。有人可以帮忙吗?例如,它运行了一半但没有完全运行,并且idk该怎么办:( :(:(
任何帮助将不胜感激-甚至有改进的方法。我在想这与输出有关,但不确定
// Creates a BoatLicense class
// And instantiates three BoatLicense objects
// The price of a licence is $25 if the boat motor is 50 HP or under
// and $38 if the HP is over 50
// Boat licenses are issued with numbers starting with 200801
using System;
public class DebugSeven4
{
public static void Main()
{
const int STARTINGNUM = 200801;
BoatLicense[] license = new BoatLicense[3];
int x;
for(x = 0; x < license.Length; ++x)
{
license[x] = new BoatLicense();
license[x].LicenseNum = (x + STARTINGNUM).ToString();
}
license[0].State = "WI";
license[1].State = "MI";
license[2].State = "MN";
license[0].MotorSizeInHP = 30;
license[1].MotorSizeInHP = 50;
license[2].MotorSizeInHP = 100;
for(x = 0; x < license.Length; ++x)
Display(license[x]);
}
static void Display(BoatLicense lic)
{
Console.WriteLine("Boat #{0} from {1} has a {2} HP motor.", lic.LicenseNum, lic.State, lic.MotorSizeInHP);
Console.WriteLine("The price for the license is {0}", lic.Price.ToString("C2"));
}
}
class BoatLicense
{
public const int HPCUTOFF = 50;
public const double LOWFEE = 25.00;
public const double HIGHFEE = 38.00;
private string licenseNum;
private string state;
private int motorSizeInHP;
private double price;
public string LicenseNum
{
get
{
return licenseNum;
}
set
{
licenseNum = value;
}
}
public string State
{
get
{
return state;
}
set
{
state = value;
}
}
public int MotorSizeInHP
{
get
{
return motorSizeInHP;
}
set
{
motorSizeInHP = value;
if(MotorSizeInHP <= HPCUTOFF)
price = LOWFEE;
else
price = HIGHFEE;
}
}
public double Price
{
get
{
return price;
}
}
}
答案 0 :(得分:0)
学习新知识需要时间。不要放弃 为了帮助您,您需要让我们知道错误消息是什么。 Microsoft有一个很好的有关如何调试代码的支持文档。
https://docs.microsoft.com/en-us/visualstudio/debugger/debugging-absolute-beginners?view=vs-2019
阅读完本文后,请使用错误消息更新问题。