When to use a Cast or Convert

前端 未结 9 2099
无人及你
无人及你 2020-11-30 00:45

I am curious to know what the difference is between a cast to say an int compared to using Convert.ToInt32(). Is there some sort of performance gai

9条回答
  •  再見小時候
    2020-11-30 01:29

    There are a lot of overloads for Convert.ToInt32 that can take for example a string. While trying to cast a string to an int will throw a compile error. The point being is they're for different uses. Convert is especially useful when you're not sure what type the object you're casting from is.

提交回复
热议问题