Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Search for an element matching the conditions and return the zero-based index of the last occurrence within the entire List in C#
To search for an element matching the conditions and return the zero-based index of the last occurrence within the entire List, the code is as follows −
Example
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<int> list = new List<int>();
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));
}
}
Output
This will produce the following output −
List elements... 200 215 310 500 600 Last Index of the satisfying condition = 4
Example
Let us now see another example −
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<int> list = new List<int>();
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));
}
}
Output
This will produce the following output −
List elements... 200 215 310 500 655 Last Index of the satisfying condition = 3
Advertisements