我有数值范围。
我想检查一个范围内的每个数字是否存在于另一个数字列表中。
我正在使用 for 循环,但它减慢了我的应用程序。
public void ShowResults()
{
// The StartNumber and EndNumber is changed depends
// upon my requirement, They are not fixed.
int StartNumber = 1 ;
int EndNumber = 1000000;
string[] list =
{
"1", "equal", "3", "perhaps", "6", "10", "378",
"1937", "28936", "26543", "937" .........,
"understood" "99993"};
for(int i = StartNumber; i<= EndNumber;i++)
{
List<int> resultList = new List<int>();
int index = Array.IndexOf(list,i.ToString());
if(index >= 0)
{
resultList.Add(i);
}
}
}