我在项目中使用了以下代码。当使用此FXCOP警告CA1305时。
string endtime = string.Format("{0:0000}{1:00}{2:00}T{3:00}{4:00}{5:00}", SchAppointment.EndTime.Year,
SchAppointment.EndTime.Month, SchAppointment.EndTime.Day,
SchAppointment.EndTime.TimeOfDay.Hours,
SchAppointment.EndTime.TimeOfDay.Minutes,
SchAppointment.EndTime.TimeOfDay.Seconds);
如何从项目中清除此警告?预先感谢。
您的代码应该喜欢:
string endtime = string.Format(
CultureInfo.CurrentCulture,
"{0:0000}{1:00}{2:00}T{3:00}{4:00}{5:00}",
SchAppointment.EndTime.Year,
SchAppointment.EndTime.Month,
SchAppointment.EndTime.Day,
SchAppointment.EndTime.TimeOfDay.Hours,
SchAppointment.EndTime.TimeOfDay.Minutes,
SchAppointment.EndTime.TimeOfDay.Seconds);
这给出了格式方法的信息以格式化数字。