I've posted something like this a bit ago and it helped out but i had issues afterwards and couldn't do anything. SO I'M BACK!
Time time1;
private void btnNewTime_Click(object sender, EventArgs e)
{
Time time1 = new Time(Convert.ToInt32(txtHour.Text.Trim(), Convert.ToInt32(txtMin.Text)));
}
and in the time class:
public Time()
{
hour = 12;
minute = 00;
}//end of Time
public Time(int Hour, int Minute)
{
hour = Hour;
minute = Minute;
}//end of Time
It's suppose to go into the parameterized constructor (the second one) But i get the error:
"does not contain a constructor that takes '1' arguments"
这是一个错字,一个错误的括号。
Time time1 = new Time(Convert.ToInt32(txtHour.Text.Trim()), Convert.ToInt32(txtMin.Text));
Time time1 = new Time
(
Convert.ToInt32(txtHour.Text.Trim()),
Convert.ToInt32(txtMin.Text)
);
Looks like you're missing a parenthesis after the first trim to close the Convert.ToInt32 (Also lose one of the last parenthesis on the end).
And, your first construct of Time
can be:
public Time()
:this(12,0)
{
}
Or, if you have VS2010/.NET4 you can now use optional parameters :
public Time(int Hour = 12, int Minute = 0)
{
hour = Hour;
minute = Minute;
}
You are only providing 1 argument to the constructor:
Time time1 = new Time(Convert.ToInt32(txtHour.Text.Trim(), Convert.ToInt32(txtMin.Text)));
You need to close the first arguments 2nd set of parenthesis:
Time time1 = new Time(Convert.ToInt32(txtHour.Text.Trim()), Convert.ToInt32(txtMin.Text));
它的错字:
Time time1 = new Time(Convert.ToInt32(txtHour.Text.Trim()), Convert.ToInt32(txtMin.Text));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.