Finding values based on array index in List<string[]>
I have an array structured like this:
{"nick", "sender", "message"}
arranged into a List<string[]>
.
Wh开发者_如何学Cat I want to do, is to search the list using the 0 index value of the array (ie nick).
I tried using:
list.Find(i => i[0].Equals(nick))
but this doesn't seem to do anything.
How would I do this?
I think this what you want
list.Where(i => i[0] == "nick")
It will return a IEnumerable<string[]>
where nick if the first element in each string[]
list.Where(x => x[0].Equals(nick));
I guess you're after:-
list.Find(i => i.Equals("nick"))
I'm also guessing that this isn't what you mean....
Perhaps you have something more like this:-
static void Main(string[] args)
{
var test = new List<string[]>() {
new String[3] { "a", "b", "b" },
new String[3] { "a", "c", "c" },
new String[3] { "b", "b", "c" },
new String[3] { "a", "d", "d" },
new String[3] { "x", "y", "z" }
};
var foundFirst = test.Find(i => i[0].Equals("a"));
var foundAll = test.Where(i => i[0].Equals("a"));
}
精彩评论