How to Find the Index of a String in a List

The Situation

You are trying to find out if a string exists in a List object.

A Solution

You could use a Find with a predicate, or try the simple method below.

private int FindStringInList(List<string> list, string str)
    return list.FindIndex(s => s == str);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s