Get min index of list in string

Following example returns the minimum index of items in list for a string.

using System;
using System.Linq;

namespace ZeroToCSharp {
    class Program {
        static void Main(string[] args) {
            var input = "ZeroToCSharpDogCherryBananaCatDog";
            var sample = new[] { "Dog", "Cat" };
            var result = sample.Min(x => input.IndexOf(x));

            //To print output
            Console.WriteLine(result);
            Console.ReadKey();
        }
    }
}

Output:

12

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x