解决方案 »

  1.   

    如果是写成这样你会弄不? “,1,2,34,5,”当然如果你愿意把indexof也叫循环,那我表示无语
      

  2.   

    indexof  内部用到了循环
      

  3.   

    可能那个公司的意思就是不让自己写foreach之类的代码“死写”,那么用A.Contains('2')就行了。
      

  4.   

      string test = "1,2,34,5";
                int i = 0;
                Console.WriteLine(IsContains(test.Split(','), i));
                Console.Read();方法体部分:
     public static bool IsContains(string[] arr, int i)
            {
                if (i == arr.Length)
                {
                    return false;
                }
                i++;
                if (arr[i - 1].Contains("p"))
                {                return true;
                }
                else
                {
                    return IsContains(arr, i);
                }
            }写的很简陋,感觉本质上和循环了没区别- -
      

  5.   

    string s = "1,2,34,5";
    bool result = s.Split(',').Contains("2");
      

  6.   

                string test = "1,2,34,5";        
                Console.WriteLine(test.Split(',').Where(x => x.Contains("2")).Count() > 0 ? true : false);
      

  7.   

                string str = "1,2,34,5";
                bool bContainedTwo = false;
                if (str[0] == '2')
                { bContainedTwo = true; }
                else if (str[1] == '2')
                { bContainedTwo = true; }
                ......
                else if (str[7] == '2')
                { bContainedTwo = true; }
                MessageBox.Show(bContainedTwo ? "2" : "不2");
    谁说这是循环我跟谁急!
      

  8.   

    split(',').Contains
    Contains,IndexOf
    Regex.IsMatch
    递归
      

  9.   

    string s = "1,2,34,5";
    bool result = s.Split(',').Contains("2");
      

  10.   


    都不try,也不判断非int,唉...
      

  11.   

    bool t=Regex.IsMatch("字符串",@"(?<=\D|^)2(?=[,,]|$)");
      

  12.   


    你这个方法跟循环都神马区别?假如人家A里面包含1W个元素,你也这样一直if else 下去?那你说跟循环都神马却别啦?其实用Contains('2')就好了,无论A里面有多少个元素也好··代码简洁
      

  13.   

    这题明显的意思是不要让你用循环,系统自带的内部循环可以的
    所以方法很多
    如:
     string A = "1,2,34,5";
                if (A.Split(',').Count(x => x == "21") > 0)
                    MessageBox.Show("包含");
                else
                    MessageBox.Show("不包含");
      

  14.   


    这里是2不是21,多写了一个1
     if (A.Split(',').Count(x => x == "2") > 0)
      

  15.   

     if((","+A+",").indexof(",2,")>-1)
     
      

  16.   

    Goto + if,   就像<天龙八部>的"天下任何招数武功,都能自行化在这‘六路折梅手’之中 "再去学学, C 语言的的Duff's device, 你就知道, 有了goto就是 "天山折梅手"using System;namespace ff {
        class Program {
            static void Main(string[] args) {
                string A = "1,2,34,5";
                int i = 0;
                int x = -1;
    lb_S:
                if('2' == A[i]) { x = i; goto lb_F; }
                ++i;
                if(i < A.Length) goto lb_S;
    lb_F:
                Console.WriteLine(-1 == x ? "not find" : ("index=" + x));
            }
        }
    }
      

  17.   


    不要被培训班的,灌输了各种教条主义.以致对goto是"谈goto色变"goto, 大有用处. 在各方舆论呼喊着,要取消 Goto时.  C#作为现代编程语言,丢弃了各种传统语言的特性,却依然雷打不动地 支持goto.大量的elseif 判断,基本可化为 goto + switch (switch,又是某些OOP痴迷者呼喊的,要消灭switch)
      

  18.   

    goto很少用,这个算不算循环了???
      

  19.   

    我觉得这题的本意不在考察面试者用index  contains 等之类简单方法来实现
      

  20.   

    string A=","+“1,2,34,5”+",";
    在用 indexof(",2,")  就可以了。 
      

  21.   


    汇编里面, 有 Jcc 等Jump系列指令
    也有 LOOPcc 等Loop系列不能认为高级语言里面的 goto 是循环. 就像不能认为汇编中 Jcc 是 LOOPcc
    虽然,在某些需求上,两者可以等价地实现
      

  22.   

    其实直接string.Contains("2")就可以了啊
      

  23.   

    plit(',').Contains
    Contains,IndexOf
    Regex.IsMatch
    递归
      

  24.   

    不用循环可以用goto任何循环都可以改写成goto比如
    while (...)
    {}
    可以写
    loopstart:
    if (!...) goto loopend:
    ...
    goto loopstart:
    loopend:
      

  25.   

    return ("," + A + ",").Contains(",2,");
      

  26.   

    写 string.split, .contains , linq, 基本是too young, too simple .这题目,不用循环, 用递归和goto, 很明显地,goto可读性远远大于递归. 
    却非要被教条主义桎梏, 写出性能和可读性都差的递归
      

  27.   

    应该是考用indexof方法,注意2加上逗号 用 比较的字符串也加上逗号

    ((","+A+",") as string).indexof(",2,") 来判断,
    不要用直接用A.indexof('2')
    国为如用是串是1,22,34,5就会出错