Supposed I have a List<SomeObject>
and have a function that return the reference of that object if available.
SomeObject GetSomeObject(List<SomeObject>, int x){
/* Search for object in list that has a properties
with value x */
if (found)
return /* The object found */
else
return NULL;
}
void DoSomething(SomeObject S){
if(S!=NULL){
/* Do action 1 */
}
else{
/* Do action 2 */
}
}
I've read somewhere that returning NULL
is not part of clean code. So I was wondering what is the equivalent code for this case.
UPDATE: I've read this question and I think my case is different. In that case, if NULL
is returned then do nothing, while I need to do something if NULL
is returned