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

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

    In the end, they all end up calling:

    System.Number.ParseInt32(string s, NumberStyles style, NumberFormatInfo info);
    

    So in summary, there will be no difference what so ever.

    Have a look in .Net Reflector to see this.

提交回复
热议问题