//C#
List<int> elements = new List<int>() { 10, 20, 31, 40 };
// ... Find index of first odd element.
int oddIndex = elements.FindIndex(x => x % 2 != 0);
Console.WriteLine(oddIndex);
Β
//C++
Vector<int> elements = { 10, 20, 31, 40 };
int oddIndex = elements.findIndex(begin, end, [](int x) {return x % 2 != 0});
cout << oddIndex << endl;
Comments
0 B
|π
/π