string aa = "abc";
            if (aa.IndexOf("abc") > 0)
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("2");
            }
            Console.ReadLine();
为什么始终是输出2 而不是1呢   如何才能得到1的结果

解决方案 »

  1.   

      if (aa.IndexOf("abc") != -1) 
                { 
                    Console.WriteLine("1"); 
                } 
      

  2.   

    改成这样就可以了:
    string aa = "abc"; 
    if (aa.IndexOf("abc") >= 0) 

        Console.WriteLine("1"); 

    else 

        Console.WriteLine("2"); 

    Console.ReadLine(); 
    C#中序号是从0开始的。
      

  3.   

    IndexOf 不是代表 包含的个数吗 abc包含在abc中 结果应该是1>0  为什么会显示2呢
      

  4.   

    aa.IndexOf("abc")==0,不是楼主所说的包含的个数,而是位置,请参照以下链接
    http://baike.baidu.com/view/1674560.htm?fr=ala0
      

  5.   

    IndexOf:第一次找到所需字符串的位置(从0开始)
    Contains:是否包含某个字符串