Cast versus parse

You generally use Parse() on a string whose value represents a valid value of the type to which you are converting.

Casting, on the other hand, is better used when you have an object of a derived type but stored in a base variable, and need to use it as its more specific type.

That is, if you have "1234" you can Parse() that into an int. But if you have

object variable = 1234;

You should cast it to get it back as an int.


Have a look here, at Mark Gravell's comprehensive answer (will answer you about converting too..).


Casting is more of a conversion of an object from a similar type. A good example is float to integer, or double to decimal. Parsing is just that; parsing. The definition or use of parsing is a bit more broad. You could write a Parse method in your own object similar to that of int.Parse or int.TryParse to convert a string to your object type. Parsing could also refer to things such as string manipulation to gather the data you need from any given string. "Parsing" does not necessarily relate to "Casting".

Another good example of casting is when using inheritance or interfaces.

public interface ICar {
    // ...
}

public class Corvette : ICar {
    // ...
}

public void Foo() {
    Corvette mycar = new Corvette();
    // Now do a cast
    ICar = (ICar)mycar;
}