如何检查具有指定长度的数组中的数据 [英] How to check for data in an array with specified length
问题描述
大家好,
任何人都可以告诉我如何检查固定长度的阵列中的数据& 我应该仅检查几个索引的数据,并忽略其余的,即使数组长度超过指定的索引。
就像我有一个固定长度为72的数组,因为索引是用户定义的,并且从4-72变化我已经为所有72个值写了条件数组。所以在1ast迭代中,我应该检查一些条件,直到该数组的12个索引长度,并且在下一次迭代中索引可能是36,所以我只需要检查 1st 该数组的最后36个索引n忽略其余的。该索引是用户定义的,它可能在4-72之间变化。那怎么处理呢?
代码如下所示:
Hi all,
Can anybody tell me how to check for data in an array with a fixed length & And I should check data only for few indices's and neglect the rest even if the array length is more than the index specified.
Like I have an array with fixed length of 72, since the index is user defined and is varied from 4-72 I have written conditions for all the 72 values of the array. So in the 1ast iteration I should check for some condition only till 12 indices length of that array and in the next iteration the index may be 36 so I need to check only 1st last 36 indices's of that array n neglect the rest. This index is user defined it may vary from 4-72. So how to handle this?
The code is shown below:
int[] errorIndexOne = new errorIndexOne[72];
if (errorIndexOne[0] == 1)
{
if (btn[0].BackColor == Color.LimeGreen)
{
btn[0].BackColor = Color.Red;
}
else
{
btn[0].BackColor = Color.LimeGreen;
}
}
if (errorIndexOne[1] == 1)
{
if (btn[1].BackColor == Color.LimeGreen)
{
btn[1].BackColor = Color.Red;
}
else
{
btn[1].BackColor = Color.LimeGreen;
}
}
if (errorIndexOne[2] == 1)
{
if (btn[2].BackColor == Color.LimeGreen)
{
btn[2].BackColor = Color.Red;
}
else
{
btn[2].BackColor = Color.LimeGreen;
}
}
if (errorIndexOne[3] == 1)
{
if (btn[3].BackColor == Color.LimeGreen)
{
btn[3].BackColor = Color.Red;
}
else
{
btn[3].BackColor = Color.LimeGreen;
}
}
if (errorIndexOne[4] == 1)
{
if (btn[4].BackColor == Color.LimeGreen)
{
btn[4].BackColor = Color.Red;
}
else
{
btn[4].BackColor = Color.LimeGreen;
}
}
if (errorIndexOne[5] == 1)
{
if (btn[5].BackColor == Color.LimeGreen)
{
btn[5].BackColor = Color.Red;
}
else
{
btn[5].BackColor = Color.LimeGreen;
}
}
.
.
.
.
.
.
if (errorIndexOne[72] == 1)
{
if (btn[72].BackColor == Color.LimeGreen)
{
btn[72].BackColor = Color.Red;
}
else
{
btn[72].BackColor = Color.LimeGreen;
}
}
推荐答案
用以下代码替换你的代码:
Replace ur code with this:
int[] errorIndexOne = new errorIndexOne[72];
for(int i=0; i<72; i++){
if (errorIndexOne[i] == 1)
{
if (btn[i].BackColor == Color.LimeGreen)
{
btn[i].BackColor = Color.Red;
}
else
{
btn[i].BackColor = Color.LimeGreen;
}
}
}
试试这个: -
Try this one:-
int[] errorIndexOne = new errorIndexOne[72];
for(int i=0; i<errorindexone.length;i++)
{
if (errorIndexOne[i] == 1)
{
if (btn[i].BackColor == Color.LimeGreen)
{
btn[i].BackColor = Color.Red;
break;
}
else
{
btn[i].BackColor = Color.LimeGreen;
}
}
}
谢谢
Prince Sharma
Thanks
Prince Sharma
试试这个
try this
int[] errorIndexOne = new errorIndexOne[72];
for(int i=0; i<72; i++){
if (errorIndexOne[i] == 1)
{
if (btn[i].BackColor == Color.LimeGreen)
{
btn[i].BackColor = Color.Red;
}
else
{
btn[i].BackColor = Color.LimeGreen;
}
}
}
这篇关于如何检查具有指定长度的数组中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!