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

后端 未结 15 1208
南笙
南笙 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:53

    (int) conversion on string won't work, so I dont test it. Convert.ToInt32 reflects as testing the value to null and THEN calling int.Parse, so should in general tend to be slower than int.Parse().

提交回复
热议问题