I want to know how to see if my list contains a string name...having this

private class item { public string itemname { get; set; }
public int val { get; set; }

I tried,

var ilst = new List<itemname>();
ilst.Add( new itemname { ilst = "AA" , val = 1 } );

and then,

ilst.Exist(name => name.itemname == "AA" );

To do this exist a more efficient way or this is ok?

Recommended Answers

All 3 Replies

List<T>.Contains() is easier to use. if (ilst.Contains("AA")) { ..

List<T>.Contains() is easier to use. if (ilst.Contains("AA")) { ..

That was my first try. The problem is that you cannot do in that way. Otherwise Visual will gives an error.

Doesn't give me an error, what error are you getting?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.