What is fastest: (int), Convert.ToInt32(x) or Int32.Parse(x)?

后端 未结 15 1418
南笙
南笙 2021-02-02 06:13

Which of the following code is fastest/best practice for converting some object x?

int myInt = (int)x;

or

int myInt = Convert.T         


        
15条回答
  •  無奈伤痛
    2021-02-02 06:39

    Best practice would be TryParse, and seeing the result of that, if it worked - otherwise you could get exceptions

提交回复
热议问题