为什么我在这里收到“输入字符串格式不正确”?

时间:2013-07-26 12:41:28

标签: c# .net

如何解决以下行中出现的输入字符串错误:

 string body = String.Format(
     "The following leave request was made by user {o}: \n Date: {1} \t Hours: {2} \t Reason: {3}", 
     username.ToString(), 
     TxtBoxDate.Text,
     DDHours.SelectedValue+DDTimeWindow.SelectedValue, 
     TxtNotes.Text);

4 个答案:

答案 0 :(得分:16)

看起来你有o字母而不是零0。尝试:

string body = String.Format("The following leave request was made by user {0}: \n Date: {1} \t Hours: {2} \t Reason: {3}", username.ToString(), TxtBoxDate.Text, DDHours.SelectedValue+DDTimeWindow.SelectedValue, TxtNotes.Text);

答案 1 :(得分:2)

简单的拼写错误,您使用的是o而不是0

答案 2 :(得分:2)

只需将'o'更改为'0'(零)。

答案 3 :(得分:2)

你有一个O而不是零{o} - > {0}

    string body =
        String.Format(
            "The following leave request was made by user {0}: \n Date: {1} \t Hours: {2} \t Reason: {3}",
            username.ToString(), 
            TxtBoxDate.Text, 
            DDHours.SelectedValue + DDTimeWindow.SelectedValue,
            TxtNotes.Text);