gpt4 book ai didi

C# StringBuilder AppendFormat 抛出 System.FormatException

转载 作者:太空宇宙 更新时间:2023-11-03 18:21:12 27 4
gpt4 key购买 nike

<分区>

我有下面这个方法,我已经简化以重现问题,谁能解释为什么会抛出系统格式异常?

我曾尝试将 @ 添加到格式字符串的开头,以防转义字符出现问题,但没有帮助。

private void doThing(StringBuilder builder, string inPrimaryKey) {
// At this point the builder.ToString() results in " <div class="v-group width-100 shadowed OrderPanel"
// and inPrimaryKey is "OrderId"

// Throws System.FormatException with the detail "Input string was not in a correct format."
builder.AppendFormat(@" @if (Model.{0} > 0) { <text>StateNonEditable</text> } else { <text>StateEditable</text> }", inPrimaryKey);
}

一些背景知识,我们正在使用此代码生成一个用于网络应用程序的 cshtml 页面,因此 stringbuilder 最初包含一些 html,然后我们在格式部分添加一些 C# MVC Razor。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com