A search for narrow resonances at high mass in the dimuon and dielectron channels has been performed by the CMS experiment at the CERN LHC, using pp collision data recorded at sqrt(s)=7 TeV. The event samples correspond to integrated luminosities of 40 inverse picobarns in the dimuon channel and 35 inverse picobarns in the dielectron channel. Heavy dilepton resonances are predicted in theoretical models with extra gauge bosons (Z') or as Kaluza-Klein graviton excitations(G_KK) in the Randall-Sundrum model. Upper limits on the inclusive cross section of Z'(G_KK) decaying to oppositely charged leptons relative to Z decaying to oppositely charged leptons are presented. These limits exclude at 95% confidence level a Z' with standard-model-like couplings below 1140 GeV, the superstring-inspired Z_psi below 887 GeV, and, for values of the coupling parameter k/M_Pl of 0.05 (0.1), Kaluza-Klein gravitons below 855 (1079) GeV.