【发布时间】:2012-09-13 21:12:30
【问题描述】:
我有一个时间值列表,格式为“09.00 AM、12.00 PM、03.00 PM”等。我们称之为 ListTimes.. 我有一个时间值(testTimeValue),格式与我传递给函数的“xx.xx AM/PM”相同。 我希望该函数将此“testTimeValue”与 ListTimes 中的每个项目进行比较,并返回最接近的时间。例如:在上述场景中,如果我将 01.00 PM 传递给函数,它应该返回 03.00 PM。
foreach (string item in listItems)
{
//I need to consider the time formats in AM and PM and do a
//proper comparison and return the closest in original format.
}
return closestTimeValue;
【问题讨论】:
-
var的使用掩盖了item的确切类型。它们是字符串,对吧? -
是的..它们是字符串..我会编辑。