gpt4 book ai didi

c# - 如何更改双数组中的项目?

转载 作者:行者123 更新时间:2023-12-03 17:50:18 24 4
gpt4 key购买 nike

如何根据简单条件更改双变量中的项目?

检查这个例子:

public partial class Form1 : Form
{

double[] vk = new double[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

...
...

void setDouble()
{
if (bunifuDropdown1.selectedIndex == 0)
{
double[] vk = new double[11] { 2, 4.86, 11.81, 28.68, 69.64, 169.13, 410.75, 997.55, 2422.61, 5883.49, 21000 };
}
if (bunifuDropdown1.selectedIndex == 1)
{
double[] vk = new double[11] { 2, 4.51, 10.14, 22.81, 51.31, 115.46, 259.78, 584.51, 1315.14, 2959.07, 21000 };
}
if (bunifuDropdown1.selectedIndex == 2)
{
double[] vk = new double[11] { 2, 6.86, 18.67, 47.33, 116.94, 286.01, 696.59, 1693.71, 4115.30, 9996.29, 21000 };
}
if (bunifuDropdown1.selectedIndex == 3)
{
double[] vk = new double[11] { 2, 6.51, 16.64, 39.43, 90.72, 206.12, 465.78, 1049.99, 2364.49, 5322.09, 21000 };
}
if (bunifuDropdown1.selectedIndex == 4)
{
double[] vk = new double[11] { 2, 6.86, 18.67, 47.33, 108.94, 264.58, 642.55, 1560.47, 3789.71, 9203.58, 21000 };
}
if (bunifuDropdown1.selectedIndex == 5)
{
double[] vk = new double[11] { 2, 6.51, 16.64, 39.43, 82.72, 186.12, 418.78, 942.24, 2120.05, 4770.11, 21000 };
}
}

执行函数后 setDouble() ,这些值没有改变。没有发现错误。我怎样才能解决这个问题?

最佳答案

您正在重新声明 vk在函数中,其中shadows原来的。
尝试这个:

public partial class Form1 : Form
{
double[] vk = new double[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

...
...

void setDouble()
{
if (bunifuDropdown1.selectedIndex == 0)
{
// NOTE: Here instead of "double[] vk = ..." we have "vk = ..."
vk = new double[11] { 2, 4.86, 11.81, 28.68, 69.64, 169.13, 410.75, 997.55, 2422.61, 5883.49, 21000 };
}
if (bunifuDropdown1.selectedIndex == 1)
{
vk = new double[11] { 2, 4.51, 10.14, 22.81, 51.31, 115.46, 259.78, 584.51, 1315.14, 2959.07, 21000 };
}
if (bunifuDropdown1.selectedIndex == 2)
{
vk = new double[11] { 2, 6.86, 18.67, 47.33, 116.94, 286.01, 696.59, 1693.71, 4115.30, 9996.29, 21000 };
}
if (bunifuDropdown1.selectedIndex == 3)
{
vk = new double[11] { 2, 6.51, 16.64, 39.43, 90.72, 206.12, 465.78, 1049.99, 2364.49, 5322.09, 21000 };
}
if (bunifuDropdown1.selectedIndex == 4)
{
vk = new double[11] { 2, 6.86, 18.67, 47.33, 108.94, 264.58, 642.55, 1560.47, 3789.71, 9203.58, 21000 };
}
if (bunifuDropdown1.selectedIndex == 5)
{
vk = new double[11] { 2, 6.51, 16.64, 39.43, 82.72, 186.12, 418.78, 942.24, 2120.05, 4770.11, 21000 };
}
}

关于c# - 如何更改双数组中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60612832/

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