代码之家  ›  专栏  ›  技术社区  ›  Vignesh kumar

在UWP中使用字符串格式(……)时,如何清除FxCop警告?

  •  0
  • Vignesh kumar  · 技术社区  · 8 年前

    我在我的项目中使用了以下代码。使用此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);
    

    提前谢谢。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Udo    8 年前

    您的代码应该是这样的:

    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);
    

    这为格式化方法提供了格式化数字的信息。

    推荐文章