I am making a method call that takes the results of four more method calls as parameters - but the methods that make these calls may or may not be null (sorry if this is a hopelessly obscure sentence). Here's the code, if it makes things more clear:
public void Inform(Room north, Room south, Room east, Room west)
{
this.north = north;
this.south = south;
this.east = east;
this.west = west;
node.Inform(north.GetNode(), south.GetNode(),
east.GetNode(), west.GetNode());
}
Basically, I want to know if there is a quick and easy way to check if an object is null and just pass "null" to the method in addition to conditional expressions - I do not need to explicitly specify null / not null for all 16 possible options.
EDIT: In response to the confusion, I want to clarify this: most of the time, the objects I pass to the method will not be zero. Typically, objects Roomexist for north, south, east, and west, and if they exist Room, the GetNode () method returns the corresponding object. I want to determine if a given exists Roomto avoid unnecessary referenced excpetions when trying to invoke a method call.
source
share