为什么这个 while 循环不会中断?
date[inc] = [0] = "01/01/2011"
dateTimePicker1.Value = {01/01/2011 00:00:00}
if 条件为更改辅助日期时间选择器时从未满足。第一个日期时间选择器必须更改一次,此代码才能工作。在这两种情况下,此代码均由 ValueChanged
触发。
有什么想法吗?
编辑:
int start;
int inc = 0;
while (true)
{
inc++;
if (Convert.ToString(dateTimePicker1.Value.ToShortDateString()) == date[inc])
{
start = inc;
inc = 0;
break;
}
}
=/=
int start;
int inc = 0;
while (true)
{
if (Convert.ToString(dateTimePicker1.Value.ToShortDateString()) == date[inc])
{
start = inc;
inc = 0;
break;
}
inc++;
}
仍然非常有帮助的评论,谢谢大家。显然由于增量而错过了第一个日期,导致无限循环。
date[inc] = [0] = "01/01/2011"
dateTimePicker1.Value = {01/01/2011 00:00:00}
The if condition is never fulfilled when changing a secondary datetimepicker. The first datetimepicker has to be changed once before this code will work. This code is triggered by a ValueChanged
in both cases.
Any ideas?
Edit:
int start;
int inc = 0;
while (true)
{
inc++;
if (Convert.ToString(dateTimePicker1.Value.ToShortDateString()) == date[inc])
{
start = inc;
inc = 0;
break;
}
}
=/=
int start;
int inc = 0;
while (true)
{
if (Convert.ToString(dateTimePicker1.Value.ToShortDateString()) == date[inc])
{
start = inc;
inc = 0;
break;
}
inc++;
}
Still very helpful comments, thanks everyone. Obviously was missing the first date because of an increment, causing an infinite loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试像这样进行比较
,或者
您也可以在
date[inc]
上执行.Trim()
它可能会对您有所帮助。编辑
查找
.Trim()
string.Equals(string1, string2, StringComparison.InvariantCultureIgnoreCase)
希望这对您有用。
Try to compare like this
OR
Also you can do
.Trim()
ondate[inc]
it might help you.EDIT
When you compare
string
things to look for.Trim()
string.Equals(string1, string2, StringComparison.InvariantCultureIgnoreCase)
Hope this works for you.
尝试:
Try:
您正在进行字符串比较:
You're doing a string comparison:
如果字符串永远不相等,则没有条件突破
if the strings are never equal, theres no condition to break out on ever