The electronic properties of semiconductor (SiC, GaN, BN, ZnO, ZnS, and CdS) nanowires and nanotubes were investigated using first-principles calculations based on density functional theory and generalized gradient approximation. Different size or surface-to-volume ratio dependences were found for the II-VI (ZnO, ZnS, and CdS) and IV-IV (SiC) and III-V (GaN and BN) nanostructures. For SiC, GaN, and BN nanostructures, the band gap decreases with the increase of the surface-to-volume ratio or the reduction of the diameter, while for ZnO, ZnS, and CdS nanostructures, the band gap increases with the increase of surface-to-volume ratio or the reduction of the diameter. The mechanism is attributed to the competition between the interaction from dangling p-like and sigma states and the quantum confinement effect.