IndexOf method returns 0 when it should had return -1 in C# / Java

前端 未结 8 542
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 10:47

A friend of mine came to me with this strange behavior which i can\'t explain, any insight view would be appreciated.

Im running VS 2005 (C# 2.0), the following code

相关标签:
8条回答
  • 2021-01-12 11:33

    More fun php actually does a way better job!

    php -r "print strpos('test','');"
    PHP Warning:  strpos(): Empty delimiter. in Command line code on line 1
    
    0 讨论(0)
  • 2021-01-12 11:36

    Quote from the C# documentation:

    If value is Empty, the return value is 0.

    The behavior that you describe is entirely as expected (at least in C#).

    0 讨论(0)
提交回复
热议问题