There are couple of ways you can do that
Method 1 - Return NULL (you will need to change the return type int to int?)
private int? f(int x)
{
if (x==1)
{
return 2*x;
}
else
{
return null;
}
}
Method 2 - You can set a default value that will represent incorrect condition.
private int f(int x)
{
if (x==1)
{
return 2*x;
}
else
{
return -1;
}
}
Method 3 - You can create TryParse kind functions where return type is bool and one parameter is out.