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

Posted by jcgarciam on Stack Overflow See other posts from Stack Overflow or by jcgarciam
Published on 2010-04-02T19:12:10Z Indexed on 2010/04/02 19:13 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

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 show the behavior

int rr = "test".IndexOf("");
Console.WriteLine(rr.ToString());

the above code, print "0" which clearly show it should have return -1

This also happen in Java where the following Class show the behavior:

public class Test{
 public static void main(String[] args){
   System.out.println("Result->"+("test".indexOf("")));
 }
}

Im running Java 1.6.0_17

© Stack Overflow or respective owner

Related posts about java

Related posts about c#