In .Net you can read a string value into another data type using either <datatype>.parse or Convert.To<DataType>.
I’m not familiar with the fundamentals of parse versus convert so I am always at a loss when asked which one is better/faster/more appropriate.
So – which way is best in what type of circumstances?
The
Convert.ToXXX()methods are for objects that might be of the correct or similar type, while.Parse()and.TryParse()are specifically for strings:If you compile with optimisation flags TryParse is very quick – it’s the best way to get a number from a string. However if you have an object that might be an int or might be a string Convert.ToInt32 is quicker.