c# - What's the difference between Convert.ToInt32 and (int)
(int)foo is simply a cast to the ( in C#) type. This is built into the CLR and requires that be a numeric variable (e.g. , , etc.) In this sense, it is very similar to a cast in C.
Convert.ToInt32 is designed to be a general conversion function. It does a good deal more than casting; namely, it can convert from any primitive type to a (most notably, parsing a ). You can see the full list of overloads for this method here on MSDN.