शर्तों से मेल खाने वाले तत्व को खोजने और संपूर्ण List में अंतिम घटना का शून्य-आधारित इंडेक्स वापस करने के लिए, कोड निम्नानुसार है:
उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
private static bool demo(int i) {
return ((i % 10) == 0);
}
public static void Main(String[] args) {
List list = new List();
list.Add(200);
list.Add(215);
list.Add(310);
list.Add(500);
list.Add(600);
Console.WriteLine("List elements...");
foreach (int i in list) {
Console.WriteLine(i);
}
Console.WriteLine("Last Index of the satisfying condition = " + list.FindLastIndex(demo));
}
}
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा:
List elements... 200 215 310 500 600 Last Index of the satisfying condition = 4
उदाहरण
आइए अब एक और उदाहरण देखें:
using System;
using System.Collections.Generic;
public class Demo {
private static bool demo(int i) {
return ((i % 2) == 0);
}
public static void Main(String[] args) {
List list = new List();
list.Add(200);
list.Add(215);
list.Add(310);
list.Add(500);
list.Add(655);
Console.WriteLine("List elements...");
foreach (int i in list) {
Console.WriteLine(i);
}
Console.WriteLine("Last Index of the satisfying condition = " + list.FindLastIndex(demo));
}
}
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा:
List elements... 200 215 310 500 655 Last Index of the satisfying condition = 3