类型不符?

jj524412718 jj524412718 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public static void DisplayByPrice(Book[] arrBooks)
{
int bookPrice = arrBooks.GetUpperBound(0) - arrBooks.GetLowerBound(0) + 1;
int [] lengths = new int [] { bookPrice };
int[] lowerBounds = new int[] { 0 };
Array arrPrices = Array.CreateInstance(Type.GetType("System.String"), lengths, lowerBounds);
for (int i = arrBooks.GetLowerBound(0); i <= arrBooks.GetUpperBound(0); i++)
arrPrices.SetValue(arrBooks[i].dblPrice,i);
Array.Sort(arrPrices, arrBooks);
foreach (Book item in arrBooks)
{
Console.WriteLine("{0} {1} {2}", item.dblPrice, item.strName, item.strAuthor);
}

}
系统提示arrPrices.SetValue(arrBooks[i].dblPrice,i);这里有错“未处理InvalidCastException”请问怎么改?
...全文
评论 6
收藏 已收藏
分享
返回顶部
jj524412718
C# 111,130 成员 642,540 内容