我的列表框中有6个项目。在列表框中选择特定项目
我想要它,所以如果我点击列表框中的第一个2,我可以设置一个随机数。我不需要知道如何制作随机数字。
我认为这将是这样的:
if (listBox1.SelectedIndex = 1)
{
int no1 = random.Next(10, 50);
}
刚过“如果”我看到了以下错误:
Cannot implicitly convert type 'int' to 'bool'
我的列表框中有6个项目。在列表框中选择特定项目
我想要它,所以如果我点击列表框中的第一个2,我可以设置一个随机数。我不需要知道如何制作随机数字。
我认为这将是这样的:
if (listBox1.SelectedIndex = 1)
{
int no1 = random.Next(10, 50);
}
刚过“如果”我看到了以下错误:
Cannot implicitly convert type 'int' to 'bool'
您需要使用两个等号检查等同性。
if (listBox1.SelectedIndex == 1)
{
int no1 = random.Next(10, 50);
}
应该是:if (listBox1.SelectedIndex == 1)
的=
运营商分配,==
是平等的。
是的在int的情况下,你不能使用=运算符来检查平等,你只需要检查使用==运算符,在bool编译器的情况下,好吧不能给出任何错误,但它可以resign.mean说。
if (listBox1.SelectedIndex == 1)
{
int no1 = random.Next(10, 50);
}
这是一个正确的布尔
的情况下,假设你有写。
bool test=false;
if(test=true)
{
//some code goes here
}
它不会给你编译器错误,它会重新分配测试。