When to use a Cast or Convert

前端 未结 9 2122
无人及你
无人及你 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:22

    string number = "123abc";

    int num;

    Int32.TryParse(number, out num); // no exception thrown at this call

    Convert.ToInt32(number); // exception IS thrown at this call

提交回复
热议问题