अंतिम मिलान तत्व खोजने के लिए, Array.LastIndexOf विधि का उपयोग करें। यदि तत्व पूर्णांक सरणी में मौजूद नहीं है तो -1 लौटाता है।
निम्न सरणी है:
int[] val = { 97, 45, 76, 21, 89, 45 };
अब, मान लीजिए आपको तत्व 45 का अंतिम इंडेक्स खोजना है। इसके लिए Array.LastIndexOf() विधि का उपयोग करें:
int res = Array.LastIndexOf(val, 45);
निम्न एक उदाहरण है:
उदाहरण
using System;
using System.Text;
public class Demo {
public static void Main() {
int[] val = { 97, 45, 76, 21, 89, 45 };
// तत्व 45 का अंतिम इंडेक्स
int res = Array.LastIndexOf(val, 45);
// इंडेक्स प्रदर्शित करें
Console.WriteLine("तत्व 45 का इंडेक्स = " + res);
}
}
आउटपुट
तत्व 45 का इंडेक्स = 5