My code is like the below one,
public object GetObjectValue(object obj, int condition)
{
if(condition > 10)
{
//exit from method
// return; gives compiler error.
}
else
{
GetObjectValue(obj,condition); // like this i need to use recursive call.
//Do stuffs
}
}
How to exit from this method. Help me.
Some points:
return nullonif(condition > 10), your next compilation error will say you need to return a value on every path (actually, that’s the same compilation error)GetObjectValue(obj,condition);may result in an infinite recursion – you call it with the same values over and over.returnstatement – that marks the end of the executed code (unless you have afinallyblock, but that’s another subject). If you don’t want toreturnthat value that’s also great, but you probably want to use it somehow:object returnedValue = GetObjectValue(obj, condition);You may be looking for something like: