Nanostructured zinc oxide material is usable in electronic device applications such as light-emitting diodes, heterojunction diode, sensors, solar cell due to its interesting electrical conductivity and optical properties. Magnesium-doped zinc oxide nanorod (NR)-nanotube (NT) films were grown by microwave-assisted chemical bath deposition to fabricate ZnO-based heterojunction diode. It is found that ZnO hexagonal nanorods turn into hexagonal nanotubes when the Mg doping ratio is increased from 1 to 10 %. The values of the optical band gap for 1 % Mg-doped ZnO NR and 10 % Mg-doped ZnO NT films are found to be 3.14 and 3.22 eV, respectively. The n-ZnO: Mg/p-Si heterojunction diodes were fabricated. The diodes exhibited a rectification behavior with ideality factor higher than unity due to the presence of surface states in the junction and series resistance. The obtained results indicate that Mg doping improves the electrical and optical properties of ZnO.