I have a method that checks whether the passed argument is present in an array. The method needs to return a bool value. Take a look at said method:
This gives me the error of 'not all code paths return value'. If I insert a 'return true' after the foreach loop, the function always returns true. Likewise if I insert 'return false' the function always returns false.
How can I write this function to give the desired effect?
Code:
private bool IPExist(string IP)
{
// We need to check if the IP exists in the
// IP array
foreach (string x in IPs)
{
if (x == IP)
{
// IP exists
return false;
}
else return true;
}
}
How can I write this function to give the desired effect?
Comment