类型不符?

jj524412718 2008-10-14 07:15:07
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”请问怎么改?
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jj524412718 2008-10-14
  • 打赏
  • 举报
回复
谢谢
wangyanboq 2008-10-14
  • 打赏
  • 举报
回复
其实就是arrBooks[i].dblPrice是什么类型

Array就定义成什么类型的Array
jj524412718 2008-10-14
  • 打赏
  • 举报
回复
哦,对了。不好意思,搞错了
jj524412718 2008-10-14
  • 打赏
  • 举报
回复
还是不对
Eagle_ice 2008-10-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wangyanboq 的回复:]
Array arrPrices = Array.CreateInstance(Type.GetType("System.String"), lengths, lowerBounds);
改成
Array arrPrices = Array.CreateInstance(Type.GetType("System.Double"), lengths, lowerBounds);
[/Quote]
恩...
wangyanboq 2008-10-14
  • 打赏
  • 举报
回复
Array arrPrices = Array.CreateInstance(Type.GetType("System.String"), lengths, lowerBounds);
改成
Array arrPrices = Array.CreateInstance(Type.GetType("System.Double"), lengths, lowerBounds);

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧