Assuming only one is nonempty, you can do this:
Vehicle instance = vehicle.Car ?? vehicle.Train ?? vehicle.Plane;
But if you want to do something useful with your instance , you just have to check typeof(instance) and translate it into the desired class.
You might want to consider only one property:
public class Vehicles { public Vehicle VehicleInstance {get; set;} }
And move the functionality so that your WorkOutTransport method can act on the Vehicle instance instead of taking care of which subclass it has. Use virtual or abstract methods in the Vehicle class and override in subclasses.
source share