初始化时间跨度变量 [英] initializing timespan variable
本文介绍了初始化时间跨度变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
TimeSpan entry=AdjustTime(int row, string colName);
private TimeSpan AdjustTime(int row, string colName)
{
string s1 = dataGridView1.Rows[row].Cells[colName].Value.ToString();
return ((!string.IsNullOrEmpty(s1)) ? TimeSpan.Parse(s1 = (s1 == "24:00:00") ? "23:59:59" : s1) : TimeSpan.Zero);
}
此代码返回的时间跨度值用于确定一个人的进入时间,如果s1 =那么函数将返回Timespan。零。问题是,在这种状态下我如何区分条目是默认值还是人员输入时间是00:00?
in this code returned timespan value is used to determines the entry time of a person and If "s1=""" so function will return Timespan.zero.the question is, in this state how I distinguish entry is default value or person entry time is "00:00"?
推荐答案
你不能直接。
您需要一些其他指标。
您可以尝试使用可空的TimeSpan:
You can't directly.
You need some other indicator.
You could try using a nullable TimeSpan:
TimeSpan? entry=AdjustTime(int row, string colName);
private TimeSpan? AdjustTime(int row, string colName)
{
string s1 = dataGridView1.Rows[row].Cells[colName].Value.ToString();
return ((!string.IsNullOrEmpty(s1)) ? TimeSpan.Parse(s1 = (s1 == "24:00:00") ? "23:59:59" : s1) : null);
}
或者您可以使用另一个不可能值作为默认值:
Or you could use another impossible value for the default:
TimeSpan entry=AdjustTime(int row, string colName);
private TimeSpan AdjustTime(int row, string colName)
{
string s1 = dataGridView1.Rows[row].Cells[colName].Value.ToString();
return ((!string.IsNullOrEmpty(s1)) ? TimeSpan.Parse(s1 = (s1 == "24:00:00") ? "23:59:59" : s1) : TimeSpan.MinValue);
}
这篇关于初始化时间跨度变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文