gpt4 book ai didi

asp.net - 无法在 Foreach 循环中将类型 "char"转换为 "string"

转载 作者:行者123 更新时间:2023-12-02 10:04:01 25 4
gpt4 key购买 nike

我有一个隐藏字段,其中填充了 ID 的 javascript 数组。当我尝试迭代隐藏字段(称为“hidExhibitsIDs”)时,它给我一个错误(在标题中)。

这是我的循环:

foreach(string exhibit in hidExhibitsIDs.Value)
{
comLinkExhibitToTask.Parameters.AddWithValue("@ExhibitID", exhibit);
}

当我将鼠标悬停在 .value 上时,它说它是“字符串”。但是,当我将“字符串展览”更改为“int展览”时,它可以工作,但给了我一个内部错误(现在不重要)。

最佳答案

您需要将字符串转换为字符串数组,以便在for循环中使用获取字符串而不是字符,如循环所示。假设隐藏字段中逗号为分隔符,则隐藏字段值将通过split转换为字符串数组。

foreach(string exhibit in hidExhibitsIDs.Value.Split(','))
{
comLinkExhibitToTask.Parameters.AddWithValue("@ExhibitID", exhibit);
}

关于asp.net - 无法在 Foreach 循环中将类型 "char"转换为 "string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12627700/

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