double avg=0;
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + arr[j];
avg = all / (j + 1);
}
它会显示double 不包含在arr中
16 个解决方案
#1
楼主, 你的arr定义的是什么类型?
你修改这段代码试试:
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString()); //here
avg = all / (j + 1);
}
你修改这段代码试试:
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString()); //here
avg = all / (j + 1);
}
#2
arr是object的?
all = all + Convert.ToDouble(arr[j]);
all = all + Convert.ToDouble(arr[j]);
#3
double all = 0;
double avg = 0;
for (int j = 0; j < arr.Count; j++)
{
//Console.Write("{0} ", arr[j]);
all += Convert.ToDouble(arr[j]);
}
avg = all / arr.Count;
#4
all = all + arr[j];
==>all = all + (double)arr[j]; 或 all = all + double.Parse(arr[j].ToString());
==>all = all + (double)arr[j]; 或 all = all + double.Parse(arr[j].ToString());
#5
1楼正解,强制转换
#6
可以结贴给分了,lz
#7
源代码运行时出现异常!?
不理解
不理解
#8
谢谢你们 搞定了 麻烦大家了!
#9
最好还是用 正则表达式去验证,不然可能会报错的
#10
#11
double all=0;
double avg=0;
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString());
avg = all / (j + 1);
}
double avg=0;
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString());
avg = all / (j + 1);
}
#12
顶顶
#13
Convert.ToDouble
#14
all = all + double.Parse(arr[j].ToString());
#15
╮(╯▽╰)╭ 打嗝~!
#16
楼上的所有方法都可以解决
#1
楼主, 你的arr定义的是什么类型?
你修改这段代码试试:
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString()); //here
avg = all / (j + 1);
}
你修改这段代码试试:
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString()); //here
avg = all / (j + 1);
}
#2
arr是object的?
all = all + Convert.ToDouble(arr[j]);
all = all + Convert.ToDouble(arr[j]);
#3
double all = 0;
double avg = 0;
for (int j = 0; j < arr.Count; j++)
{
//Console.Write("{0} ", arr[j]);
all += Convert.ToDouble(arr[j]);
}
avg = all / arr.Count;
#4
all = all + arr[j];
==>all = all + (double)arr[j]; 或 all = all + double.Parse(arr[j].ToString());
==>all = all + (double)arr[j]; 或 all = all + double.Parse(arr[j].ToString());
#5
1楼正解,强制转换
#6
可以结贴给分了,lz
#7
源代码运行时出现异常!?
不理解
不理解
#8
谢谢你们 搞定了 麻烦大家了!
#9
最好还是用 正则表达式去验证,不然可能会报错的
#10
#11
double all=0;
double avg=0;
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString());
avg = all / (j + 1);
}
double avg=0;
for (int j = 0; j < arr.Count; j++)
{
Console.Write("{0} ", arr[j]);
all = all + double.Parse(arr[j].ToString());
avg = all / (j + 1);
}
#12
顶顶
#13
Convert.ToDouble
#14
all = all + double.Parse(arr[j].ToString());
#15
╮(╯▽╰)╭ 打嗝~!
#16
楼上的所有方法都可以解决