How to switch between display and hide

I want to switch doc.objects between display and hidden.
It is Ok to switch from display to hidden, but I can’t get the hidden object in the doc.objects after then,
so it fail to switch back from hidden to display.
How to solve it?

public class MmaTest : Rhino.Commands.Command
	public override string EnglishName { get { return "mmaTest"; } }
	bool visible = true;

	protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
		if (visible == true)
			foreach (var obj in doc.Objects)
				doc.Objects.Hide(obj, false);
			visible = false;
			foreach (var obj in doc.Objects) //get obj fail!!!
				doc.Objects.Show(obj, false);
			visible = true;
		return Rhino.Commands.Result.Success;

I think in that case you should use GetObjectList with the required settings, where HiddenObjects can be set to true.