C# Extension Method: Array - LastIndexOf

CSharp · Console

/Program.cs

// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002174/array-lastindexof

// @nuget: Z.ExtensionMethods

using System;

public class Program
{
	public static void Main()
	{
        String[] strings = { "the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog", "in", "the", "barn" };
       
        // Searches for the last occurrence of the duplicated value.
        String searchString = "the";

		// C# Extension Method: Array - LastIndexOf
        int index = strings.LastIndexOf(searchString);

        Console.WriteLine("The first occurrence of \"{0}\" is at index {1}.",
                         searchString, index);
	}
}
;