A search is presented for new high-mass resonances decaying into electron ormuon pairs. The search uses proton-proton collision data at a centre-of-massenergy of 13 TeV collected by the CMS experiment at the LHC in 2016,corresponding to an integrated luminosity of 36 fb$^{-1}$. Observations are inagreement with standard model expectations. Upper limits on the product of anew resonance production cross section and branching fraction to dileptons arecalculated in a model-independent manner. This permits the interpretation ofthe limits in models predicting a narrow dielectron or dimuon resonance. A scanof different intrinsic width hypotheses is performed. Limits are set on themasses of various hypothetical particles. For the Z$'_\mathrm{SSM}$(Z$'_{\psi}$) particle, which arises in the sequential standard model(superstring-inspired model), a lower mass limit of 4.50 (3.90) TeV is set at95% confidence level. The lightest Kaluza-Klein graviton arising in theRandall-Sundrum model of extra dimensions, with coupling parameters$k/\overline{M}_\mathrm{Pl}$ of 0.01, 0.05, and 0.10, is excluded at 95%confidence level below 2.10, 3.65, and 4.25 TeV, respectively. In a simplifiedmodel of dark matter production via a vector or axial vector mediator, limitsat 95% confidence level are obtained on the masses of the dark matter particleand its mediator.