Do you mean you want to add i
to values
if there is no i
in that list?
Use FindIndex
to check if list contains i it will return the index. If it is not, it will return -1.
List<int> values = new List<int>();
private void CheckCondition()
{
for (int i = 0; i < 5; i++)
{
int idx = values.FindIndex(item => item == i || item > i);
if(idx == -1)
{
values.Add(i);
break;
}
}
}
5
solved How to compare number with all number in List not loop List?