The cantilever tip of a nanoswitch in close proximity to the ground plate is considered with account of electrostatic, elastic, van der Waals (Casimir), and also contact repulsive forces. The van der Waals (Casimir) and contact repulsive forces are computed for a Si cantilever and either Au or Ni ground plates using the Lifshitz theory and the method of pairwise summation with account of surface roughness. It is shown that at short separations an impact of the van der Waals (Casimir) force leads to the pull-in and collapse of a cantilever onto the ground plate if the contact repulsion is disregarded. Taking into consideration contact repulsion, the nanoswitch is demonstrated to have the stable cyclic behavior with no pull-in when switching voltage on and off.