Search code examples
uwpfxcopstring.format

How to clear FxCop warnings while using string.Format(......) in UWP?


I have used the below code in my project.While using this FxCop warning CA1305 occurs.

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

how can i clear this warning from my project? thanks in advance.


Solution

  • Your code should like this:

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

    This gives the Format method the information to format the numbers.