C#用于组合框中的循环

本文关键字:循环 用于 组合 | 更新日期: 2023-09-27 18:24:20

我试图在label1上显示汇率,但我不知道应该在label1.Text =中键入什么。有人能带我去吗

String[] arr = new string[2];
arr[0] = "US"
arr[1] = "SG"
Combobox1.Items.AddRange(arr);
Combobox2.Items.AddRange(arr);

combobox1combobox2

double[,] value = new double [2,2];
for(int I =0; I<2; I++)
{
   value[0,0] = 1; // basically if I chose Combobox1 US and Combobox2 US the rate is 1;
   value[0,1] = 1.24; // US to SG
   value[1,0] = 0.80; // SG to US
   value[1,1] = 1; // SG to SG
   Label1.Text = 
}

C#用于组合框中的循环

我假设您想要打印出值(1、1.24、0.08或1)。

您可以创建一个变量并使用if语句设置其值,然后在Label1 中打印该值

double labelValue;
if (value[0,0]) labelValue = 1;
else if (value[0,1]) labelValue = 1.24;
else if (value[1,0]) labelValue = 0.80;
else if (value[1,1]) labelValue = 1;
Label1.Text = labelValue;

你在找这样的东西吗?

double[,] value = new double[,] { { 1, 1.24 }, { 0.8, 1 } };
Label1.Text = value[Combobox1.SelectedIndex, Combobox2.SelectedIndex].ToString();