list.IndexOf(a) // returns -1 if 'a' could not be fount in 'list'
请注意,在将其添加到列表后更改了"a",因此当您使用index时,它已经是另一个值.这样它会起作用:
while(0 != 1) { list.Add(a); charCount = a.ToString().Length; if (charCount >= 1000) { Console.WriteLine(list.IndexOf(a)); break; } BigInteger c = a; // a = b; // this is the Fibonacci sequence b = a + c; // }