No, you can't keep Danse if you side with the Railroad in Fallout 4. The only factions that you can keep Danse with are the Brotherhood of Steel and the Minutemen, provided you don't make enemies of the BoS. Doing an Institute or Railroad playthrough will eventually result in Danse turning hostile to you.