Which is fast comparison: Convert.ToInt32(stringValue)==intValue or stringValue==intValue.ToString()

后端 未结 8 2057
执念已碎
执念已碎 2021-02-13 18:34

While developing my application i came across some comparison stuff here was it:

    string str = \"12345\";
    int j = 12345;
    if (str == j.ToString())
             


        
8条回答
  •  感情败类
    2021-02-13 18:57

    If performance is near identical, go with the version that is more readable.

    Personally, I find the .ToString() approach to be easier to understand and less prone to possible casting issues that the other approach has.

提交回复
热议问题