I have a string array:
string[] Animals = {"Cat", "Dog", "Fish"};
I then want to determine which element contains the sequence "is" and return that entire element; in this case "fish"
If I want to find "gh", it does not exist in the list, so it should return the first element, in this case "Cat"
I've tried this linq code, but i don't think I'm doing the lambda part right.
int index = Animals.Where(x => x.IndexOf("is") >= 0).First().IndexOf("is")
string result = index > 0 ? Animals[index] : Animals[0];
This code throws this error:
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: value
I think I'm close, I just can't seem to get it.
This method obviously isn't fool proof, it should return the first instance of "is" which could be problematic. My potential list is fairly small and the index word is always unique.