The Self-Taught Programmer

Recipes from real-world experience with

How to Find the Index of a String in a List

leave a comment »

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);

Written by Jim McMullen

October 17, 2011 at 3:54 pm

Posted in How-To

Tagged with ,

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 )

Google photo

You are commenting using your Google 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

%d bloggers like this: