我不确定为什么我说这个错误是诚实的.
private int hour
{
get;
set
{
//make sure hour is positive
if (value < MIN_HOUR)
{
hour = 0;
MessageBox.Show("Hour value " + value.ToString() + " cannot be negative. Reset to " + MIN_HOUR.ToString(),
"Invalid Hour", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
//take the modulus to ensure always less than 24 hours
//works even if the value is already within range, or value equal to 24
hour = value % MAX_HOUR;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也试过做一个实际的财产:
public int hour
{ …Run Code Online (Sandbox Code Playgroud) 我被告知要让我的课抽象:
public abstract class Airplane_Abstract
Run Code Online (Sandbox Code Playgroud)
并制作一个名为move virtual的方法
public virtual void Move()
{
//use the property to ensure that there is a valid position object
double radians = PlanePosition.Direction * (Math.PI / 180.0);
// change the x location by the x vector of the speed
PlanePosition.X_Coordinate += (int)(PlanePosition.Speed * Math.Cos(radians));
// change the y location by the y vector of the speed
PlanePosition.Y_Coordinate += (int)(PlanePosition.Speed * Math.Sin(radians));
}
Run Code Online (Sandbox Code Playgroud)
而另外4种方法应该是"纯虚拟方法".究竟是什么?
它们现在看起来都像这样:
public virtual void TurnRight()
{
// turn right relative to the …Run Code Online (Sandbox Code Playgroud) 我想从文本框中放置一个值,让"12"表示字符串临时变量中的某个位置.然后我想在说"10"之后放置另一个值,但是之间有一个:介于两者之间.两者都来自文本框并经过验证,因此它们只能是数字.
有这个问题的程序,通过表单将文件添加到txt文件,但问题没有说什么关于Fstream所以我认为它没有处理它,但我不知道这个问题是什么意思.
lstEmployees.Items.Add("No records found.");
Run Code Online (Sandbox Code Playgroud) 我将我的基类更改abstract为项目,现在我收到以下错误:
无法创建抽象类或接口的实例
我收到错误是因为abstract不允许命名新的类实例吗?
newPlane = new Airplane_Abstract(name, position);
Run Code Online (Sandbox Code Playgroud) 我遇到了同样的问题,上周我只是从父类来看:
public ExtendedTime(int Hour, int Minute, String TimeZone) :base(hour, minute)
{
timeZone = TimeZone;
}//end of ExtendedTime
Run Code Online (Sandbox Code Playgroud)
:base(hour,minute)是我有这个错误的地方.小时和分钟都表示同样的问题.现在通常我会说,我错过了一些东西,但我尝试了这一点,并没有做任何好的遗憾.
在父类中,小时和分钟声明如下:
internal int hour;
internal int minute;
Run Code Online (Sandbox Code Playgroud)
我有安装和吸气设置.
现在,这是我的代码
int number = 0;
DirectoryInfo di = new DirectoryInfo(scpath + @"Screenshots\");
if (di.Exists) {
} else {
di.Create();
}
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save(di + "Screenshot_" + number, ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
程序截取屏幕截图(有效),然后保存镜头.我想做的是,有程序检查,看看屏幕截图是否存在"Screenshot_*",如果没有创建它.如果确实如此,则递增直到它达到"Screenshot_"末尾未使用的数字.不确定如何处理这个问题,因为文件和递增更多.我正在考虑for循环,但我现在正在玩它.
我正在为一所学校的项目工作(申请我的CIS学士学位),我遇到了一个类功能问题.
public static int GetNumberCreated()
{
// return the total number of airplanes created using the class as the blueprint
return numberCreated; // returns the number of airplanes created
}//end of public int GetNumberCreated()
Run Code Online (Sandbox Code Playgroud)
这是一个程序,可以返回到目前为止在这个小型C#程序中你制作了多少架飞机的价值.我在开头宣布numberCreated:
private int numberCreated;
Run Code Online (Sandbox Code Playgroud)
我得到了经典错误"非静态字段,方法或属性需要一个对象引用"我已经做了大量的研究,试图弄清楚发生了什么,但我什么也没做到.
然而,我确实在类的底部设置了一个属性,以便表单能够访问变量:
public int NumberCreated { get; set; }
Run Code Online (Sandbox Code Playgroud)
我还尝试将属性更改为:
public int NumberCreated { get { return numberCreated; } set { numberCreated = value; } }
Run Code Online (Sandbox Code Playgroud)
没有运气.>>"
我究竟做错了什么?
是否可以更改DateTime返回的值?或者至少将其分配给变量然后更改该变量?
internal int hour;
internal int minute;
DateTime time = DateTime.Now;
public int incrementHour(int step)
{
if (step > 0 && hour < 24)
{
//step = step % hour;
hour = (hour + step) % 24;
time.AddHours(hour);
return hour;
}//end of if
else
{
MessageBox.Show("Please enter a positive number.");
return 0;
}//end of else
}//end of incrementHour
Run Code Online (Sandbox Code Playgroud)
Addhours从外观上看并没有做任何事情.