var myObject = something as String; if (myObject != null) { // successfully cast } else { // cast failed }